fix(workflow): tighten tsgo types in workflow editor

This commit is contained in:
yyh
2026-03-25 18:35:51 +08:00
parent 3571bee55f
commit ab6993b6e7
10 changed files with 150 additions and 67 deletions

View File

@ -1,4 +1,4 @@
import type { VarInInspect } from '@/types/workflow'
import type { FileResponse, VarInInspect } from '@/types/workflow'
import { getProcessedFilesFromResponse } from '@/app/components/base/file-uploader/utils'
import {
checkJsonSchemaDepth,
@ -14,6 +14,14 @@ type UploadedFileLike = {
upload_file_id?: string
}
const isFileResponse = (value: unknown): value is FileResponse => {
if (!value || typeof value !== 'object' || Array.isArray(value))
return false
return ['related_id', 'filename', 'mime_type', 'transfer_method', 'type', 'url', 'upload_file_id', 'remote_url']
.every(key => key in value)
}
export const getValueEditorState = (currentVar: VarInInspect) => {
const showTextEditor = currentVar.value_type === 'secret' || currentVar.value_type === 'string' || currentVar.value_type === 'number'
const showBoolEditor = typeof currentVar.value === 'boolean'
@ -40,9 +48,15 @@ export const getValueEditorState = (currentVar: VarInInspect) => {
export const formatInspectFileValue = (currentVar: VarInInspect) => {
if (currentVar.value_type === 'file')
return currentVar.value ? getProcessedFilesFromResponse([currentVar.value]) : []
if (currentVar.value_type === 'array[file]' || (currentVar.type === VarInInspectType.system && currentVar.name === 'files'))
return currentVar.value && currentVar.value.length > 0 ? getProcessedFilesFromResponse(currentVar.value) : []
return isFileResponse(currentVar.value) ? getProcessedFilesFromResponse([currentVar.value]) : []
if (currentVar.value_type === 'array[file]' || (currentVar.type === VarInInspectType.system && currentVar.name === 'files')) {
if (!Array.isArray(currentVar.value) || !currentVar.value.every(isFileResponse))
return []
return currentVar.value.length > 0 ? getProcessedFilesFromResponse(currentVar.value) : []
}
return []
}