Skip to content

Commit bd8b4ad

Browse files
committed
Implement copy-only mode for the prompt field when no web configurations are available
- don't require file selection to function - configuration should only be required in 'api' mode, as user can copy to clipboard from the web mode - in web mode, when there is no web configuration, the 'copy to clipboard' should be the default action (with 'send' completely hidden), also copy on 'enter' key press. - add translations to [Pasted text] ├── apps │ └── editor │ └── src │ ├── i18n │ │ └── translations │ │ └── views │ │ └── prompt │ │ └── handlers │ │ └── voice-input.ts │ └── views │ └── prompt │ ├── backend │ │ └── message-handlers │ │ └── handle-voice-input.ts │ └── frontend │ └── Main │ └── MainView │ └── MainView.tsx ├── packages │ └── ui │ └── src │ └── components │ └── editor │ └── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── components │ │ │ ├── Tooltip.module.scss │ │ │ ├── Tooltip.tsx │ │ │ └── index.ts │ │ ├── hooks │ │ │ ├── use-drag-drop.ts │ │ │ ├── use-dropdown.ts │ │ │ ├── use-ghost-text.ts │ │ │ ├── use-handlers │ │ │ │ ├── handle-copy.ts │ │ │ │ ├── handle-cut.ts │ │ │ │ ├── handle-input-change.ts │ │ │ │ ├── handle-input-click.ts │ │ │ │ ├── handle-key-down.ts │ │ │ │ ├── handle-paste.ts │ │ │ │ ├── handle-submit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ ├── use-handlers.ts │ │ │ │ └── utils.ts │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ ├── Template │ │ ├── Template.module.scss │ │ ├── Template.tsx │ │ └── index.ts │ └── shared │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── src └── examples └── weekdays.py
1 parent fb7beb7 commit bd8b4ad

4 files changed

Lines changed: 35 additions & 43 deletions

File tree

‎apps/editor/src/i18n/translations/views/prompt/handlers/voice-input.ts‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,21 @@ export const translations = {
185185
bg: 'Не е намерена конфигурация'
186186
},
187187
'views.prompt.handlers.voice-input.warning.no-config.detail': {
188-
en: 'Add a "Voice Input" configuration in settings to use this feature.',
189-
pl: 'Dodaj konfigurację "Wprowadzanie głosowe" w ustawieniach, aby użyć tej funkcji.',
190-
'zh-cn': '在设置中添加“语音输入”配置以使用此功能。',
191-
ja: 'この機能を使用するには、設定で「音声入力」設定を追加してください。',
192-
'zh-tw': '在設定中新增「語音輸入」配置以使用此功能。',
193-
de: 'Fügen Sie eine "Spracheingabe"-Konfiguration in den Einstellungen hinzu, um diese Funktion zu nutzen.',
194-
es: 'Agregue una configuración de "Entrada de voz" en la configuración para usar esta función.',
195-
fr: 'Ajoutez une configuration "Saisie vocale" dans les paramètres pour utiliser cette fonctionnalité.',
196-
'pt-br':
197-
'Adicione uma configuração de "Entrada de Voz" nas configurações para usar este recurso.',
198-
ru: 'Добавьте конфигурацию "Голосовой ввод" в настройках для использования этой функции.',
199-
ko: '이 기능을 사용하려면 설정에서 "음성 입력" 구성을 추가하세요.',
200-
it: 'Aggiungi una configurazione "Input vocale" nelle impostazioni per utilizzare questa funzione.',
201-
tr: 'Bu özelliği kullanmak için ayarlara bir "Ses Girişi" yapılandırması ekleyin.',
202-
cs: 'Chcete-li tuto funkci používat, přidejte v nastavení konfiguraci "Hlasový vstup".',
203-
hu: 'Ennek a funkciónak a használatához adjon hozzá egy "Hangbemenet" konfigurációt a beállításokban.',
204-
bg: 'Добавете конфигурация "Гласов вход" в настройките, за да използвате тази функция.'
188+
en: 'No API configurations found. Add one to use this feature.',
189+
pl: 'Nie znaleziono konfiguracji API. Dodaj jedną, aby korzystać z tej funkcji.',
190+
'zh-cn': '未找到 API 配置。添加一个以使用此功能。',
191+
ja: 'API設定が見つかりません。この機能を使用するには設定を追加してください。',
192+
'zh-tw': '找不到 API 配置。新增一個以使用此功能。',
193+
de: 'Keine API-Konfigurationen gefunden. Fügen Sie eine hinzu, um diese Funktion zu nutzen.',
194+
es: 'No se encontraron configuraciones de API. Añade una para usar esta función.',
195+
fr: 'Aucune configuration d\'API trouvée. Ajoutez-en une pour utiliser cette fonctionnalité.',
196+
'pt-br': 'Nenhuma configuração de API encontrada. Adicione uma para usar este recurso.',
197+
ru: 'Конфигурации API не найдены. Добавьте одну, чтобы использовать эту функцию.',
198+
ko: 'API 구성을 찾을 수 없습니다. 이 기능을 사용하려면 하나를 추가하세요.',
199+
it: 'Nessuna configurazione API trovata. Aggiungine una per usare questa funzione.',
200+
tr: 'API yapılandırması bulunamadı. Bu özelliği kullanmak için bir tane ekleyin.',
201+
cs: 'Nebyly nalezeny žádné konfigurace API. Přidejte jednu, abyste mohli tuto funkci používat.',
202+
hu: 'Nem találhatók API konfigurációk. Adjon hozzá egyet a funkció használatához.',
203+
bg: 'Не са намерени API конфигурации. Добавете една, за да използвате тази функция.'
205204
}
206205
} as const

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,13 @@ const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
136136
export const MainView: React.FC<Props> = (props) => {
137137
const { t } = use_translation()
138138

139-
const is_in_edit_context_prompt_type =
140-
(props.mode == MODE.WEB && props.web_prompt_type == 'edit-files') ||
141-
(props.mode == MODE.API && props.api_prompt_type == 'edit-files')
142-
143-
const is_in_ask_about_context_prompt_type =
144-
props.mode == MODE.WEB && props.web_prompt_type == 'ask-about-files'
145-
146139
const show_edit_format_selector =
147140
(props.mode == MODE.WEB && props.web_prompt_type == 'edit-files') ||
148141
(props.mode == MODE.API && props.api_prompt_type == 'edit-files')
149142

150143
let warning: string | undefined
151-
if (
152-
(props.mode == MODE.API && props.api_configurations.length == 0) ||
153-
(props.mode == MODE.WEB && props.web_configurations.length == 0)
154-
) {
144+
if (props.mode == MODE.API && props.api_configurations.length == 0) {
155145
warning = 'Add a configuration'
156-
} else if (
157-
(is_in_edit_context_prompt_type || is_in_ask_about_context_prompt_type) &&
158-
props.token_count == 0
159-
) {
160-
warning = 'Select files'
161146
}
162147

163148
const { current_invocation_count, handle_invocation_count_change } =
@@ -301,6 +286,7 @@ export const MainView: React.FC<Props> = (props) => {
301286

302287
<div className={styles['chat-input-container']}>
303288
<UiPromptField
289+
is_copy_only={props.mode == MODE.WEB && props.web_configurations.length == 0}
304290
value={props.instructions}
305291
chat_history={props.chat_history}
306292
on_change={handle_input_change}

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type PromptFieldProps = {
8080
warning?: string
8181
voice_input_push_to_talk?: boolean
8282
token_count?: number
83+
is_copy_only?: boolean
8384
translations: {
8485
invocation_count: string
8586
voice_input: string
@@ -156,7 +157,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
156157

157158
useEffect(() => {
158159
const has_submit_button =
159-
(!props.is_web_mode || (props.is_web_mode && props.is_connected)) &&
160+
(!props.is_copy_only && (!props.is_web_mode || (props.is_web_mode && props.is_connected))) &&
160161
!props.is_recording &&
161162
!!props.value
162163

@@ -168,7 +169,8 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
168169
props.is_recording,
169170
props.is_web_mode,
170171
props.is_connected,
171-
props.prompt_type
172+
props.prompt_type,
173+
props.is_copy_only
172174
])
173175

174176
useEffect(() => {
@@ -413,7 +415,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
413415
: props.translations.voice_input
414416
}
415417
details={is_mac ? '⇧⌘Space' : 'Ctrl+Shift+Space'}
416-
offset={props.is_web_mode && !props.is_connected ? 12 : 28}
418+
offset={props.is_copy_only || (props.is_web_mode && !props.is_connected) ? 12 : 28}
417419
align="right"
418420
/>
419421
)}
@@ -597,8 +599,8 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
597599
</div>
598600

599601
<div className={styles['footer__right__submit']} ref={dropdown_ref}>
600-
{(!props.is_web_mode ||
601-
(props.is_web_mode && props.is_connected)) && (
602+
{(!props.is_copy_only && (!props.is_web_mode ||
603+
(props.is_web_mode && props.is_connected))) && (
602604
<>
603605
<div
604606
className={styles['footer__right__invocation-count']}
@@ -749,7 +751,7 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
749751
/>
750752
</>
751753
)}
752-
{props.is_web_mode && !props.is_connected && (
754+
{(props.is_copy_only || (props.is_web_mode && !props.is_connected)) && (
753755
<>
754756
{props.is_recording ? (
755757
<button

‎packages/ui/src/components/editor/common/prompts/PromptField/hooks/use-handlers/handle-submit.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ export const create_handle_submit =
99
with_control?: boolean
1010
) => {
1111
e.stopPropagation()
12-
const should_submit_with_control = with_control || e.ctrlKey || e.metaKey
13-
if (should_submit_with_control) {
14-
props.on_submit_with_control()
12+
13+
if (props.is_copy_only) {
14+
props.on_copy()
1515
} else {
16-
props.on_submit()
16+
const should_submit_with_control = with_control || e.ctrlKey || e.metaKey
17+
if (should_submit_with_control) {
18+
props.on_submit_with_control()
19+
} else {
20+
props.on_submit()
21+
}
1722
}
1823
state.set_history_index(-1)
1924
}

0 commit comments

Comments
 (0)