-
Notifications
You must be signed in to change notification settings - Fork 98
[wip] Add custom prompt management feature #3088
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,22 @@ | ||
| import { | ||
| Chip, | ||
| CircularProgress, | ||
| IconButton, | ||
| Paper, | ||
| TextField, | ||
| Tooltip, | ||
| } from '@mui/material' | ||
| import { | ||
| AddCircleOutline as AddCircleOutlineIcon, | ||
| Code as CodeIcon, | ||
| Masks as MasksIcon, | ||
| PlayArrow as PlayArrowIcon, | ||
| Refresh as RefreshIcon, | ||
| Send as SendIcon, | ||
| Stop as StopIcon, | ||
| } from '@mui/icons-material' | ||
| import { | ||
| Chip, | ||
| CircularProgress, | ||
| IconButton, | ||
| Paper, | ||
| TextField, | ||
| Tooltip, | ||
| } from '@mui/material' | ||
| import { CONNECTION_STATES } from './store/webSocketSlice' | ||
| import { extractYAMLFromText } from './promptSchema' | ||
| import { humanize, validateMessage } from './chatUtils' | ||
| import { makeStyles } from '@mui/styles' | ||
| import { | ||
|
|
@@ -24,6 +26,8 @@ import { | |
| useSettings, | ||
| useWebSocketActions, | ||
| } from './store/useChatStore' | ||
| import CreatePromptDialog from './CreatePromptDialog' | ||
| import PromptEditor from './PromptEditor' | ||
| import PropTypes from 'prop-types' | ||
| import React, { useEffect, useRef, useState } from 'react' | ||
| import SlashCommandModal from './SlashCommandModal' | ||
|
|
@@ -121,6 +125,11 @@ export default function ChatInput({ | |
| const [commandMenuAnchor, setCommandMenuAnchor] = useState(null) | ||
| const slashNavigationRef = useRef(null) | ||
|
|
||
| // Custom prompt creation state | ||
| const [createPromptDialogOpen, setCreatePromptDialogOpen] = useState(false) | ||
| const [promptEditorOpen, setPromptEditorOpen] = useState(false) | ||
| const [promptEditorInitialYAML, setPromptEditorInitialYAML] = useState(null) | ||
|
|
||
| const { settings } = useSettings() | ||
| const { personas } = usePersonas() | ||
| const { prompts, renderPrompt } = usePrompts() | ||
|
|
@@ -189,6 +198,34 @@ export default function ChatInput({ | |
| setCommandMenuAnchor(null) | ||
| } | ||
|
|
||
| const handleCreatePromptClick = () => { | ||
| setCreatePromptDialogOpen(true) | ||
| } | ||
|
|
||
| const handleYAMLGenerated = (aiResponse) => { | ||
| console.log('ChatInput: Received AI response, length:', aiResponse.length) | ||
|
|
||
| // Extract YAML from the AI response | ||
| const yamlBlocks = extractYAMLFromText(aiResponse) | ||
| const yamlContent = yamlBlocks.length > 0 ? yamlBlocks[0] : aiResponse | ||
|
|
||
| console.log('ChatInput: Extracted YAML length:', yamlContent.length) | ||
| console.log('ChatInput: First 500 chars:', yamlContent.substring(0, 500)) | ||
| console.log( | ||
| 'ChatInput: Last 500 chars:', | ||
| yamlContent.substring(Math.max(0, yamlContent.length - 500)) | ||
| ) | ||
|
|
||
| // Open the prompt editor with the generated YAML | ||
| setPromptEditorInitialYAML(yamlContent) | ||
| setPromptEditorOpen(true) | ||
| } | ||
|
|
||
| const handlePromptEditorClose = () => { | ||
| setPromptEditorOpen(false) | ||
| setPromptEditorInitialYAML(null) | ||
| } | ||
|
|
||
| const handleSendMessage = () => { | ||
| const validation = validateMessage(message) | ||
|
|
||
|
|
@@ -307,8 +344,8 @@ export default function ChatInput({ | |
|
|
||
| const getCharacterCountClass = () => { | ||
| const length = message.length | ||
| if (length > 9000) return 'error' | ||
| if (length > 8000) return 'warning' | ||
| if (length > 90000) return 'error' | ||
| if (length > 80000) return 'warning' | ||
| return '' | ||
|
Comment on lines
+347
to
349
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix character limit display inconsistency. The validation logic checks for 90,000/80,000 character limits, but the UI displays a maximum of 10,000. According to the PR description, the message limit was increased to 100K, so the display should reflect the actual limits. Apply this diff to fix the display: className={`${classes.characterCount} ${getCharacterCountClass()}`}
>
- {message.length}/10000
+ {message.length}/100000
</span>Also applies to: 421-421 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
@@ -475,6 +512,20 @@ export default function ChatInput({ | |
| </span> | ||
| </Tooltip> | ||
|
|
||
| {/* Create custom prompt button */} | ||
| <Tooltip title="Create custom prompt with AI"> | ||
| <span> | ||
| <IconButton | ||
| className={classes.commandMenuButton} | ||
| onClick={handleCreatePromptClick} | ||
| disabled={disabled || isTyping} | ||
| color="secondary" | ||
| > | ||
| <AddCircleOutlineIcon /> | ||
| </IconButton> | ||
| </span> | ||
| </Tooltip> | ||
|
|
||
| <Tooltip | ||
| title={ | ||
| canSend | ||
|
|
@@ -517,6 +568,20 @@ export default function ChatInput({ | |
| onSubmit={handleModalSubmit} | ||
| disabled={isTyping} | ||
| /> | ||
|
|
||
| {/* Create prompt dialog */} | ||
| <CreatePromptDialog | ||
| open={createPromptDialogOpen} | ||
| onClose={() => setCreatePromptDialogOpen(false)} | ||
| onYAMLGenerated={handleYAMLGenerated} | ||
| /> | ||
|
|
||
| {/* Prompt editor */} | ||
| <PromptEditor | ||
| open={promptEditorOpen} | ||
| onClose={handlePromptEditorClose} | ||
| initialYAML={promptEditorInitialYAML} | ||
| /> | ||
| </Paper> | ||
| ) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.