chore: add ai renames at more places (#4244)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -6,13 +6,28 @@
|
|||||||
@close="$emit('hide-modal')"
|
@close="$emit('hide-modal')"
|
||||||
>
|
>
|
||||||
<template #body>
|
<template #body>
|
||||||
|
<div class="flex gap-1">
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="editingName"
|
v-model="editingName"
|
||||||
|
class="flex-grow"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
:label="t('action.label')"
|
:label="t('action.label')"
|
||||||
input-styles="floating-input"
|
input-styles="floating-input"
|
||||||
@submit="addRequest"
|
@submit="addRequest"
|
||||||
/>
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-if="canDoRequestNameGeneration"
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:icon="IconSparkle"
|
||||||
|
:disabled="isGenerateRequestNamePending"
|
||||||
|
class="rounded-md"
|
||||||
|
:class="{
|
||||||
|
'animate-pulse': isGenerateRequestNamePending,
|
||||||
|
}"
|
||||||
|
:title="t('ai_experiments.generate_request_name')"
|
||||||
|
@click="generateRequestName(props.requestContext)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="flex space-x-2">
|
<span class="flex space-x-2">
|
||||||
@@ -39,6 +54,9 @@ import { useI18n } from "@composables/i18n"
|
|||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
|
import { useRequestNameGeneration } from "~/composables/ai-experiments"
|
||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import IconSparkle from "~icons/lucide/sparkles"
|
||||||
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
@@ -47,10 +65,12 @@ const props = withDefaults(
|
|||||||
defineProps<{
|
defineProps<{
|
||||||
show: boolean
|
show: boolean
|
||||||
loadingState: boolean
|
loadingState: boolean
|
||||||
|
requestContext: HoppRESTRequest | null
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
show: false,
|
show: false,
|
||||||
loadingState: false,
|
loadingState: false,
|
||||||
|
requestContext: null,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,6 +81,12 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const editingName = ref("")
|
const editingName = ref("")
|
||||||
|
|
||||||
|
const {
|
||||||
|
generateRequestName,
|
||||||
|
isGenerateRequestNamePending,
|
||||||
|
canDoRequestNameGeneration,
|
||||||
|
} = useRequestNameGeneration(editingName)
|
||||||
|
|
||||||
const tabs = useService(RESTTabService)
|
const tabs = useService(RESTTabService)
|
||||||
watch(
|
watch(
|
||||||
() => props.show,
|
() => props.show,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
@submit="editRequest"
|
@submit="editRequest"
|
||||||
/>
|
/>
|
||||||
<HoppButtonSecondary
|
<HoppButtonSecondary
|
||||||
v-if="showGenerateRequestNameButton"
|
v-if="canDoRequestNameGeneration"
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
:icon="IconSparkle"
|
:icon="IconSparkle"
|
||||||
:disabled="isGenerateRequestNamePending"
|
:disabled="isGenerateRequestNamePending"
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
'animate-pulse': isGenerateRequestNamePending,
|
'animate-pulse': isGenerateRequestNamePending,
|
||||||
}"
|
}"
|
||||||
:title="t('ai_experiments.generate_request_name')"
|
:title="t('ai_experiments.generate_request_name')"
|
||||||
@click="generateRequestName"
|
@click="generateRequestName(props.requestContext)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -53,12 +53,7 @@ import { useI18n } from "@composables/i18n"
|
|||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { HoppRESTRequest } from "@hoppscotch/data"
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { useVModel } from "@vueuse/core"
|
import { useVModel } from "@vueuse/core"
|
||||||
import * as E from "fp-ts/Either"
|
import { useRequestNameGeneration } from "~/composables/ai-experiments"
|
||||||
import { computed, ref } from "vue"
|
|
||||||
|
|
||||||
import { useSetting } from "~/composables/settings"
|
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
|
||||||
import { platform } from "~/platform"
|
|
||||||
import IconSparkle from "~icons/lucide/sparkles"
|
import IconSparkle from "~icons/lucide/sparkles"
|
||||||
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -84,58 +79,13 @@ const emit = defineEmits<{
|
|||||||
(e: "update:modelValue", value: string): void
|
(e: "update:modelValue", value: string): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const ENABLE_AI_EXPERIMENTS = useSetting("ENABLE_AI_EXPERIMENTS")
|
|
||||||
|
|
||||||
const editingName = useVModel(props, "modelValue")
|
const editingName = useVModel(props, "modelValue")
|
||||||
|
|
||||||
const currentUser = useReadonlyStream(
|
const {
|
||||||
platform.auth.getCurrentUserStream(),
|
generateRequestName,
|
||||||
platform.auth.getCurrentUser()
|
canDoRequestNameGeneration,
|
||||||
)
|
isGenerateRequestNamePending,
|
||||||
|
} = useRequestNameGeneration(editingName)
|
||||||
const isGenerateRequestNamePending = ref(false)
|
|
||||||
|
|
||||||
const showGenerateRequestNameButton = computed(() => {
|
|
||||||
// Request generation applies only to the authenticated state
|
|
||||||
if (!currentUser.value) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return ENABLE_AI_EXPERIMENTS.value && !!platform.experiments?.aiExperiments
|
|
||||||
})
|
|
||||||
|
|
||||||
const generateRequestName = async () => {
|
|
||||||
const generateRequestNameForPlatform =
|
|
||||||
platform.experiments?.aiExperiments?.generateRequestName
|
|
||||||
|
|
||||||
if (!props.requestContext || !generateRequestNameForPlatform) {
|
|
||||||
toast.error(t("request.generate_name_error"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = true
|
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "EXPERIMENTS_GENERATE_REQUEST_NAME_WITH_AI",
|
|
||||||
platform: "rest",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await generateRequestNameForPlatform(
|
|
||||||
JSON.stringify(props.requestContext)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (result && E.isLeft(result)) {
|
|
||||||
toast.error(t("request.generate_name_error"))
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = false
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
editingName.value = result.right
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const editRequest = () => {
|
const editRequest = () => {
|
||||||
if (editingName.value.trim() === "") {
|
if (editingName.value.trim() === "") {
|
||||||
|
|||||||
@@ -8,14 +8,29 @@
|
|||||||
>
|
>
|
||||||
<template #body>
|
<template #body>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
<div class="flex gap-1">
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="requestName"
|
v-model="requestName"
|
||||||
|
class="flex-grow"
|
||||||
styles="relative flex"
|
styles="relative flex"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
:label="t('request.name')"
|
:label="t('request.name')"
|
||||||
input-styles="floating-input"
|
input-styles="floating-input"
|
||||||
@submit="saveRequestAs"
|
@submit="saveRequestAs"
|
||||||
/>
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-if="canDoRequestNameGeneration"
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:icon="IconSparkle"
|
||||||
|
:disabled="isGenerateRequestNamePending"
|
||||||
|
class="rounded-md"
|
||||||
|
:class="{
|
||||||
|
'animate-pulse': isGenerateRequestNamePending,
|
||||||
|
}"
|
||||||
|
:title="t('ai_experiments.generate_request_name')"
|
||||||
|
@click="generateRequestName(requestContext)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label class="p-4">
|
<label class="p-4">
|
||||||
{{ t("collection.select_location") }}
|
{{ t("collection.select_location") }}
|
||||||
@@ -69,6 +84,7 @@ import * as TE from "fp-ts/TaskEither"
|
|||||||
import { pipe } from "fp-ts/function"
|
import { pipe } from "fp-ts/function"
|
||||||
import { cloneDeep } from "lodash-es"
|
import { cloneDeep } from "lodash-es"
|
||||||
import { computed, nextTick, reactive, ref, watch } from "vue"
|
import { computed, nextTick, reactive, ref, watch } from "vue"
|
||||||
|
import { useRequestNameGeneration } from "~/composables/ai-experiments"
|
||||||
import { GQLError } from "~/helpers/backend/GQLClient"
|
import { GQLError } from "~/helpers/backend/GQLClient"
|
||||||
import {
|
import {
|
||||||
createRequestInCollection,
|
createRequestInCollection,
|
||||||
@@ -86,6 +102,7 @@ import { platform } from "~/platform"
|
|||||||
import { GQLTabService } from "~/services/tab/graphql"
|
import { GQLTabService } from "~/services/tab/graphql"
|
||||||
import { RESTTabService } from "~/services/tab/rest"
|
import { RESTTabService } from "~/services/tab/rest"
|
||||||
import { TeamWorkspace } from "~/services/workspace.service"
|
import { TeamWorkspace } from "~/services/workspace.service"
|
||||||
|
import IconSparkle from "~icons/lucide/sparkles"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -144,8 +161,26 @@ const reqName = computed(() => {
|
|||||||
return gqlRequestName.value
|
return gqlRequestName.value
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const requestContext = computed(() => {
|
||||||
|
if (props.request) {
|
||||||
|
return props.request
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.mode === "rest") {
|
||||||
|
return RESTTabs.currentActiveTab.value.document.request
|
||||||
|
}
|
||||||
|
|
||||||
|
return GQLTabs.currentActiveTab.value.document.request
|
||||||
|
})
|
||||||
|
|
||||||
const requestName = ref(reqName.value)
|
const requestName = ref(reqName.value)
|
||||||
|
|
||||||
|
const {
|
||||||
|
canDoRequestNameGeneration,
|
||||||
|
generateRequestName,
|
||||||
|
isGenerateRequestNamePending,
|
||||||
|
} = useRequestNameGeneration(requestName)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [RESTTabs.currentActiveTab.value, GQLTabs.currentActiveTab.value],
|
() => [RESTTabs.currentActiveTab.value, GQLTabs.currentActiveTab.value],
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@@ -6,13 +6,28 @@
|
|||||||
@close="emit('hide-modal')"
|
@close="emit('hide-modal')"
|
||||||
>
|
>
|
||||||
<template #body>
|
<template #body>
|
||||||
|
<div class="flex gap-1 items-center">
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="editingName"
|
v-model="editingName"
|
||||||
|
class="flex-grow"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
:label="t('action.label')"
|
:label="t('action.label')"
|
||||||
input-styles="floating-input"
|
input-styles="floating-input"
|
||||||
@submit="addRequest"
|
@submit="addRequest"
|
||||||
/>
|
/>
|
||||||
|
<HoppButtonSecondary
|
||||||
|
v-if="canDoRequestNameGeneration"
|
||||||
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
|
:icon="IconSparkle"
|
||||||
|
:disabled="isGenerateRequestNamePending"
|
||||||
|
class="rounded-md"
|
||||||
|
:class="{
|
||||||
|
'animate-pulse': isGenerateRequestNamePending,
|
||||||
|
}"
|
||||||
|
:title="t('ai_experiments.generate_request_name')"
|
||||||
|
@click="generateRequestName(props.requestContext)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="flex space-x-2">
|
<span class="flex space-x-2">
|
||||||
@@ -33,11 +48,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from "vue"
|
|
||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
|
import { HoppRESTRequest } from "@hoppscotch/data"
|
||||||
import { useService } from "dioc/vue"
|
import { useService } from "dioc/vue"
|
||||||
|
import { ref, watch } from "vue"
|
||||||
|
|
||||||
|
import { useRequestNameGeneration } from "~/composables/ai-experiments"
|
||||||
import { GQLTabService } from "~/services/tab/graphql"
|
import { GQLTabService } from "~/services/tab/graphql"
|
||||||
|
import IconSparkle from "~icons/lucide/sparkles"
|
||||||
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
@@ -47,6 +66,7 @@ const tabs = useService(GQLTabService)
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
show: boolean
|
show: boolean
|
||||||
folderPath?: string
|
folderPath?: string
|
||||||
|
requestContext: HoppRESTRequest | null
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -62,6 +82,12 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const editingName = ref("")
|
const editingName = ref("")
|
||||||
|
|
||||||
|
const {
|
||||||
|
generateRequestName,
|
||||||
|
isGenerateRequestNamePending,
|
||||||
|
canDoRequestNameGeneration,
|
||||||
|
} = useRequestNameGeneration(editingName)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.show,
|
() => props.show,
|
||||||
(show) => {
|
(show) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<template #body>
|
<template #body>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="requestUpdateData.name"
|
v-model="editingName"
|
||||||
class="flex-grow"
|
class="flex-grow"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
:label="t('action.label')"
|
:label="t('action.label')"
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
@submit="saveRequest"
|
@submit="saveRequest"
|
||||||
/>
|
/>
|
||||||
<HoppButtonSecondary
|
<HoppButtonSecondary
|
||||||
v-if="showGenerateRequestNameButton"
|
v-if="canDoRequestNameGeneration"
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
:icon="IconSparkle"
|
:icon="IconSparkle"
|
||||||
:disabled="isGenerateRequestNamePending"
|
:disabled="isGenerateRequestNamePending"
|
||||||
@@ -51,13 +51,9 @@
|
|||||||
import { useI18n } from "@composables/i18n"
|
import { useI18n } from "@composables/i18n"
|
||||||
import { useToast } from "@composables/toast"
|
import { useToast } from "@composables/toast"
|
||||||
import { HoppGQLRequest } from "@hoppscotch/data"
|
import { HoppGQLRequest } from "@hoppscotch/data"
|
||||||
import * as E from "fp-ts/Either"
|
import { ref, watch } from "vue"
|
||||||
import { computed, ref, watch } from "vue"
|
import { useRequestNameGeneration } from "~/composables/ai-experiments"
|
||||||
|
|
||||||
import { useSetting } from "~/composables/settings"
|
|
||||||
import { useReadonlyStream } from "~/composables/stream"
|
|
||||||
import { editGraphqlRequest } from "~/newstore/collections"
|
import { editGraphqlRequest } from "~/newstore/collections"
|
||||||
import { platform } from "~/platform"
|
|
||||||
import IconSparkle from "~icons/lucide/sparkles"
|
import IconSparkle from "~icons/lucide/sparkles"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
@@ -76,75 +72,30 @@ const emit = defineEmits<{
|
|||||||
(e: "hide-modal"): void
|
(e: "hide-modal"): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const requestUpdateData = ref({ name: null as string | null })
|
const editingName = ref("")
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.editingRequestName,
|
() => props.editingRequestName,
|
||||||
(val) => {
|
(val) => {
|
||||||
requestUpdateData.value.name = val
|
editingName.value = val
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const ENABLE_AI_EXPERIMENTS = useSetting("ENABLE_AI_EXPERIMENTS")
|
const {
|
||||||
|
canDoRequestNameGeneration,
|
||||||
const currentUser = useReadonlyStream(
|
generateRequestName,
|
||||||
platform.auth.getCurrentUserStream(),
|
isGenerateRequestNamePending,
|
||||||
platform.auth.getCurrentUser()
|
} = useRequestNameGeneration(editingName)
|
||||||
)
|
|
||||||
|
|
||||||
const isGenerateRequestNamePending = ref(false)
|
|
||||||
|
|
||||||
const showGenerateRequestNameButton = computed(() => {
|
|
||||||
// Request generation applies only to the authenticated state
|
|
||||||
if (!currentUser.value) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return ENABLE_AI_EXPERIMENTS.value && !!platform.experiments?.aiExperiments
|
|
||||||
})
|
|
||||||
|
|
||||||
const generateRequestName = async () => {
|
|
||||||
const generateRequestNameForPlatform =
|
|
||||||
platform.experiments?.aiExperiments?.generateRequestName
|
|
||||||
|
|
||||||
if (!props.requestContext || !generateRequestNameForPlatform) {
|
|
||||||
toast.error(t("request.generate_name_error"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = true
|
|
||||||
|
|
||||||
platform.analytics?.logEvent({
|
|
||||||
type: "EXPERIMENTS_GENERATE_REQUEST_NAME_WITH_AI",
|
|
||||||
platform: "gql",
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await generateRequestNameForPlatform(
|
|
||||||
JSON.stringify(props.requestContext)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (result && E.isLeft(result)) {
|
|
||||||
toast.error(t("request.generate_name_error"))
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = false
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
requestUpdateData.value.name = result.right
|
|
||||||
|
|
||||||
isGenerateRequestNamePending.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const saveRequest = () => {
|
const saveRequest = () => {
|
||||||
if (!requestUpdateData.value.name) {
|
if (!editingName.value) {
|
||||||
toast.error(`${t("collection.invalid_name")}`)
|
toast.error(`${t("collection.invalid_name")}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdated = {
|
const requestUpdated = {
|
||||||
...(props.request as any),
|
...(props.request as any),
|
||||||
name: requestUpdateData.value.name || (props.request as any).name,
|
name: editingName.value || (props.request as any).name,
|
||||||
}
|
}
|
||||||
|
|
||||||
editGraphqlRequest(props.folderPath, props.requestIndex, requestUpdated)
|
editGraphqlRequest(props.folderPath, props.requestIndex, requestUpdated)
|
||||||
@@ -153,7 +104,7 @@ const saveRequest = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hideModal = () => {
|
const hideModal = () => {
|
||||||
requestUpdateData.value = { name: null }
|
editingName.value = ""
|
||||||
emit("hide-modal")
|
emit("hide-modal")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
<CollectionsGraphqlAddRequest
|
<CollectionsGraphqlAddRequest
|
||||||
:show="showModalAddRequest"
|
:show="showModalAddRequest"
|
||||||
:folder-path="editingFolderPath"
|
:folder-path="editingFolderPath"
|
||||||
|
:request-context="requestContext"
|
||||||
@add-request="onAddRequest($event)"
|
@add-request="onAddRequest($event)"
|
||||||
@hide-modal="displayModalAddRequest(false)"
|
@hide-modal="displayModalAddRequest(false)"
|
||||||
/>
|
/>
|
||||||
@@ -330,6 +331,10 @@ const filteredCollections = computed(() => {
|
|||||||
return filteredCollections
|
return filteredCollections
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const requestContext = computed(() => {
|
||||||
|
return tabs.currentActiveTab.value.document.request
|
||||||
|
})
|
||||||
|
|
||||||
const displayModalAdd = (shouldDisplay: boolean) => {
|
const displayModalAdd = (shouldDisplay: boolean) => {
|
||||||
showModalAdd.value = shouldDisplay
|
showModalAdd.value = shouldDisplay
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
<CollectionsAddRequest
|
<CollectionsAddRequest
|
||||||
:show="showModalAddRequest"
|
:show="showModalAddRequest"
|
||||||
:loading-state="modalLoadingState"
|
:loading-state="modalLoadingState"
|
||||||
|
:request-context="requestContext"
|
||||||
@add-request="onAddRequest"
|
@add-request="onAddRequest"
|
||||||
@hide-modal="displayModalAddRequest(false)"
|
@hide-modal="displayModalAddRequest(false)"
|
||||||
/>
|
/>
|
||||||
@@ -790,6 +791,10 @@ const addRequest = (payload: {
|
|||||||
displayModalAddRequest(true)
|
displayModalAddRequest(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requestContext = computed(() => {
|
||||||
|
return tabs.currentActiveTab.value.document.request
|
||||||
|
})
|
||||||
|
|
||||||
const onAddRequest = (requestName: string) => {
|
const onAddRequest = (requestName: string) => {
|
||||||
const newRequest = {
|
const newRequest = {
|
||||||
...cloneDeep(tabs.currentActiveTab.value.document.request),
|
...cloneDeep(tabs.currentActiveTab.value.document.request),
|
||||||
|
|||||||
78
packages/hoppscotch-common/src/composables/ai-experiments.ts
Normal file
78
packages/hoppscotch-common/src/composables/ai-experiments.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { computed, Ref, ref } from "vue"
|
||||||
|
import { useReadonlyStream } from "./stream"
|
||||||
|
import { platform } from "~/platform"
|
||||||
|
import { useSetting } from "./settings"
|
||||||
|
import { HoppGQLRequest, HoppRESTRequest } from "@hoppscotch/data"
|
||||||
|
import { useToast } from "@composables/toast"
|
||||||
|
import { useI18n } from "@composables/i18n"
|
||||||
|
import * as E from "fp-ts/Either"
|
||||||
|
import { useRoute } from "vue-router"
|
||||||
|
|
||||||
|
export const useRequestNameGeneration = (targetNameRef: Ref<string>) => {
|
||||||
|
const toast = useToast()
|
||||||
|
const t = useI18n()
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const targetPage = computed(() => {
|
||||||
|
return route.fullPath.includes("/graphql") ? "gql" : "rest"
|
||||||
|
})
|
||||||
|
|
||||||
|
const isGenerateRequestNamePending = ref(false)
|
||||||
|
|
||||||
|
const generateRequestNameForPlatform =
|
||||||
|
platform.experiments?.aiExperiments?.generateRequestName
|
||||||
|
|
||||||
|
const currentUser = useReadonlyStream(
|
||||||
|
platform.auth.getCurrentUserStream(),
|
||||||
|
platform.auth.getCurrentUser()
|
||||||
|
)
|
||||||
|
|
||||||
|
const ENABLE_AI_EXPERIMENTS = useSetting("ENABLE_AI_EXPERIMENTS")
|
||||||
|
|
||||||
|
const canDoRequestNameGeneration = computed(() => {
|
||||||
|
// Request generation applies only to the authenticated state
|
||||||
|
if (!currentUser.value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return ENABLE_AI_EXPERIMENTS.value && !!platform.experiments?.aiExperiments
|
||||||
|
})
|
||||||
|
|
||||||
|
const generateRequestName = async (
|
||||||
|
requestContext: HoppRESTRequest | HoppGQLRequest | null
|
||||||
|
) => {
|
||||||
|
if (!requestContext || !generateRequestNameForPlatform) {
|
||||||
|
toast.error(t("request.generate_name_error"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isGenerateRequestNamePending.value = true
|
||||||
|
|
||||||
|
platform.analytics?.logEvent({
|
||||||
|
type: "EXPERIMENTS_GENERATE_REQUEST_NAME_WITH_AI",
|
||||||
|
platform: targetPage.value,
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await generateRequestNameForPlatform(
|
||||||
|
JSON.stringify(requestContext)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result && E.isLeft(result)) {
|
||||||
|
toast.error(t("request.generate_name_error"))
|
||||||
|
|
||||||
|
isGenerateRequestNamePending.value = false
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
targetNameRef.value = result.right
|
||||||
|
|
||||||
|
isGenerateRequestNamePending.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
generateRequestName,
|
||||||
|
isGenerateRequestNamePending,
|
||||||
|
canDoRequestNameGeneration,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -126,6 +126,7 @@ const getHoppReqAuth = (req: InsomniaRequestResource): HoppRESTAuth => {
|
|||||||
isPKCE: false,
|
isPKCE: false,
|
||||||
tokenEndpoint: replaceVarTemplating(auth.accessTokenUrl ?? ""),
|
tokenEndpoint: replaceVarTemplating(auth.accessTokenUrl ?? ""),
|
||||||
},
|
},
|
||||||
|
addTo: "HEADERS",
|
||||||
}
|
}
|
||||||
else if (auth.type === "bearer")
|
else if (auth.type === "bearer")
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user