feat(ai-exp): add support for custom request naming scheme (#4703)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Govind.S.B 2025-01-29 20:24:39 +05:30 committed by GitHub
parent 104f628862
commit d436af587c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 75 additions and 46 deletions

View file

@ -802,6 +802,8 @@
"ai_request_naming_style_camel_case": "Camel Case ( camelCase )",
"ai_request_naming_style_snake_case": "Snake Case ( snake_case )",
"ai_request_naming_style_pascal_case": "Pascal Case ( PascalCase )",
"ai_request_naming_style_custom": "Custom",
"ai_request_naming_style_custom_placeholder": "Enter your custom naming style template...",
"sync": "Synchronise",
"sync_collections": "Collections",
"sync_description": "These settings are synced to cloud.",

View file

@ -50,6 +50,7 @@ export const useRequestNameGeneration = (targetNameRef: Ref<string>) => {
}
const namingStyle = useSetting("AI_REQUEST_NAMING_STYLE").value
const customNamingStyle = useSetting("CUSTOM_NAMING_STYLE").value
isGenerateRequestNamePending.value = true
@ -60,7 +61,7 @@ export const useRequestNameGeneration = (targetNameRef: Ref<string>) => {
const result = await generateRequestNameForPlatform(
JSON.stringify(requestContext),
namingStyle
namingStyle === "CUSTOM" ? customNamingStyle : namingStyle
)
if (result && E.isLeft(result)) {

View file

@ -78,6 +78,8 @@ export type SettingsDef = {
| "camelCase"
| "snake_case"
| "PascalCase"
| "CUSTOM"
CUSTOM_NAMING_STYLE: string
}
export const getDefaultSettings = (): SettingsDef => ({
@ -129,6 +131,7 @@ export const getDefaultSettings = (): SettingsDef => ({
HAS_OPENED_SPOTLIGHT: false,
ENABLE_AI_EXPERIMENTS: true,
AI_REQUEST_NAMING_STYLE: "DESCRIPTIVE_WITH_SPACES",
CUSTOM_NAMING_STYLE: "",
})
type ApplySettingPayload = {

View file

@ -87,53 +87,70 @@
<label class="text-secondaryLight">{{
t("settings.ai_request_naming_style")
}}</label>
<div class="flex">
<tippy
interactive
trigger="click"
theme="popover"
:on-shown="() => namingStyleTippyActions?.focus()"
>
<HoppSmartSelectWrapper>
<HoppButtonSecondary
class="flex flex-1 !justify-start rounded-none pr-8"
:label="activeNamingStyle?.label"
outline
/>
</HoppSmartSelectWrapper>
<template #content="{ hide }">
<div
ref="namingStyleTippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.escape="hide()"
>
<HoppSmartLink
v-for="style in supportedNamingStyles"
:key="style"
class="flex flex-1"
@click="
() => {
AI_REQUEST_NAMING_STYLE = style.id
hide()
}
"
<div class="flex flex-col space-y-4">
<div class="flex">
<tippy
interactive
trigger="click"
theme="popover"
:on-shown="() => namingStyleTippyActions?.focus()"
>
<HoppSmartSelectWrapper>
<HoppButtonSecondary
class="flex flex-1 !justify-start rounded-none pr-8"
:label="activeNamingStyle?.label"
outline
/>
</HoppSmartSelectWrapper>
<template #content="{ hide }">
<div
ref="namingStyleTippyActions"
class="flex flex-col focus:outline-none"
tabindex="0"
@keyup.escape="hide()"
>
<HoppSmartItem
:label="style.label"
:active-info-icon="
AI_REQUEST_NAMING_STYLE === style.id
<HoppSmartLink
v-for="style in supportedNamingStyles"
:key="style.id"
class="flex flex-1"
@click="
() => {
AI_REQUEST_NAMING_STYLE = style.id
hide()
}
"
:info-icon="
AI_REQUEST_NAMING_STYLE === style.id
? IconDone
: null
"
/>
</HoppSmartLink>
</div>
</template>
</tippy>
>
<HoppSmartItem
:label="style.label"
:active-info-icon="
AI_REQUEST_NAMING_STYLE === style.id
"
:info-icon="
AI_REQUEST_NAMING_STYLE === style.id
? IconDone
: null
"
/>
</HoppSmartLink>
</div>
</template>
</tippy>
</div>
<div
v-if="AI_REQUEST_NAMING_STYLE === 'CUSTOM'"
class="flex"
>
<textarea
v-model="CUSTOM_NAMING_STYLE"
class="flex flex-1 bg-primaryLight px-4 py-2 rounded border border-dividerLight focus:border-divider transition"
:placeholder="
t(
'settings.ai_request_naming_style_custom_placeholder'
)
"
rows="4"
/>
</div>
</div>
</div>
</div>
@ -274,6 +291,7 @@ const EXPAND_NAVIGATION = useSetting("EXPAND_NAVIGATION")
const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
const ENABLE_AI_EXPERIMENTS = useSetting("ENABLE_AI_EXPERIMENTS")
const AI_REQUEST_NAMING_STYLE = useSetting("AI_REQUEST_NAMING_STYLE")
const CUSTOM_NAMING_STYLE = useSetting("CUSTOM_NAMING_STYLE")
const supportedNamingStyles = [
{
@ -292,6 +310,10 @@ const supportedNamingStyles = [
id: "PascalCase" as const,
label: t("settings.ai_request_naming_style_pascal_case"),
},
{
id: "CUSTOM" as const,
label: t("settings.ai_request_naming_style_custom"),
},
]
const activeNamingStyle = computed(() =>

View file

@ -79,6 +79,7 @@ const SettingsDefSchema = z.object({
.string()
.optional()
.catch("DESCRIPTIVE_WITH_SPACES"),
CUSTOM_NAMING_STYLE: z.string().optional().catch(""),
})
const HoppRESTRequestSchema = entityReference(HoppRESTRequest)