feat: support optional query content (#1097)

Co-authored-by: Garfield Dai <dai.hai@foxmail.com>
This commit is contained in:
Joel
2023-09-10 00:12:34 +08:00
committed by GitHub
parent 1ade70aa1e
commit 2d5ad0d208
36 changed files with 547 additions and 289 deletions

View File

@@ -1,22 +1,32 @@
import { UserInputFormItem, } from '@/types/app'
import { PromptVariable } from '@/models/debug'
import type { UserInputFormItem } from '@/types/app'
import type { PromptVariable } from '@/models/debug'
export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | null) => {
if (!useInputs) return []
if (!useInputs)
return []
const promptVariables: PromptVariable[] = []
useInputs.forEach((item: any) => {
const type = item['text-input'] ? 'string' : 'select'
const content = type === 'string' ? item['text-input'] : item['select']
if (type === 'string') {
const isParagraph = !!item.paragraph
const [type, content] = (() => {
if (isParagraph)
return ['paragraph', item.paragraph]
if (item['text-input'])
return ['string', item['text-input']]
return ['select', item.select]
})()
if (type === 'string' || type === 'paragraph') {
promptVariables.push({
key: content.variable,
name: content.label,
required: content.required,
type: 'string',
type,
max_length: content.max_length,
options: [],
})
} else {
}
else {
promptVariables.push({
key: content.variable,
name: content.label,
@@ -32,29 +42,30 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] |
export const promptVariablesToUserInputsForm = (promptVariables: PromptVariable[]) => {
const userInputs: UserInputFormItem[] = []
promptVariables.filter(({ key, name }) => {
if (key && key.trim() && name && name.trim()) {
if (key && key.trim() && name && name.trim())
return true
}
return false
}).forEach((item: any) => {
if (item.type === 'string') {
if (item.type === 'string' || item.type === 'paragraph') {
userInputs.push({
'text-input': {
[item.type === 'string' ? 'text-input' : 'paragraph']: {
label: item.name,
variable: item.key,
required: item.required === false ? false : true, // default true
required: item.required !== false, // default true
max_length: item.max_length,
default: ''
default: '',
},
} as any)
} else {
}
else {
userInputs.push({
'select': {
select: {
label: item.name,
variable: item.key,
required: item.required === false ? false : true, // default true
required: item.required !== false, // default true
options: item.options,
default: ''
default: '',
},
} as any)
}