mirror of
https://github.com/open-webui/open-webui
synced 2025-06-25 09:47:41 +00:00
Merge pull request #12974 from holmlund/fix/prompts-international
fix: improve international character handling in prompt commands
This commit is contained in:
commit
6101067ea4
@ -8,6 +8,7 @@
|
|||||||
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
||||||
import AccessControlModal from '../common/AccessControlModal.svelte';
|
import AccessControlModal from '../common/AccessControlModal.svelte';
|
||||||
import { user } from '$lib/stores';
|
import { user } from '$lib/stores';
|
||||||
|
import { slugify } from '$lib/utils';
|
||||||
|
|
||||||
export let onSubmit: Function;
|
export let onSubmit: Function;
|
||||||
export let edit = false;
|
export let edit = false;
|
||||||
@ -25,8 +26,15 @@
|
|||||||
|
|
||||||
let showAccessControlModal = false;
|
let showAccessControlModal = false;
|
||||||
|
|
||||||
$: if (!edit) {
|
let hasManualEdit = false;
|
||||||
command = title !== '' ? `${title.replace(/\s+/g, '-').toLowerCase()}` : '';
|
|
||||||
|
$: if (!edit && !hasManualEdit) {
|
||||||
|
command = title !== '' ? slugify(title) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track manual edits
|
||||||
|
function handleCommandInput(e: Event) {
|
||||||
|
hasManualEdit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitHandler = async () => {
|
const submitHandler = async () => {
|
||||||
@ -64,7 +72,7 @@
|
|||||||
command = prompt.command.at(0) === '/' ? prompt.command.slice(1) : prompt.command;
|
command = prompt.command.at(0) === '/' ? prompt.command.slice(1) : prompt.command;
|
||||||
content = prompt.content;
|
content = prompt.content;
|
||||||
|
|
||||||
accessControl = prompt?.access_control ?? null;
|
accessControl = prompt?.access_control ?? {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -125,6 +133,7 @@
|
|||||||
class=" w-full bg-transparent outline-hidden"
|
class=" w-full bg-transparent outline-hidden"
|
||||||
placeholder={$i18n.t('Command')}
|
placeholder={$i18n.t('Command')}
|
||||||
bind:value={command}
|
bind:value={command}
|
||||||
|
on:input={handleCommandInput}
|
||||||
required
|
required
|
||||||
disabled={edit}
|
disabled={edit}
|
||||||
/>
|
/>
|
||||||
|
@ -1302,3 +1302,17 @@ export const convertOpenApiToToolPayload = (openApiSpec) => {
|
|||||||
|
|
||||||
return toolPayload;
|
return toolPayload;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const slugify = (str: string): string => {
|
||||||
|
return str
|
||||||
|
// 1. Normalize: separate accented letters into base + combining marks
|
||||||
|
.normalize("NFD")
|
||||||
|
// 2. Remove all combining marks (the accents)
|
||||||
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
|
// 3. Replace any sequence of whitespace with a single hyphen
|
||||||
|
.replace(/\s+/g, "-")
|
||||||
|
// 4. Remove all characters except alphanumeric characters and hyphens
|
||||||
|
.replace(/[^a-zA-Z0-9-]/g, "")
|
||||||
|
// 5. Convert to lowercase
|
||||||
|
.toLowerCase();
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user