support custom output schema in tool node
This commit is contained in:
parent
e4d72f3442
commit
07d7965e3b
@ -76,6 +76,7 @@ export type Tool = {
|
||||
description: any
|
||||
parameters: ToolParameter[]
|
||||
labels: string[]
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
||||
export type ToolCredential = {
|
||||
|
@ -58,6 +58,7 @@ const ToolItem: FC<Props> = ({
|
||||
tool_label: payload.label[language],
|
||||
title: payload.label[language],
|
||||
is_team_authorization: provider.is_team_authorization,
|
||||
output_schema: payload.output_schema,
|
||||
params,
|
||||
})
|
||||
}}
|
||||
|
@ -27,4 +27,5 @@ export type ToolDefaultValue = {
|
||||
title: string
|
||||
is_team_authorization: boolean
|
||||
params: Record<string, any>
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
@ -235,7 +235,29 @@ const formatItem = (
|
||||
}
|
||||
|
||||
case BlockEnum.Tool: {
|
||||
res.vars = TOOL_OUTPUT_STRUCT
|
||||
const {
|
||||
output_schema,
|
||||
} = data as ToolNodeType
|
||||
if (!output_schema) {
|
||||
res.vars = TOOL_OUTPUT_STRUCT
|
||||
}
|
||||
else {
|
||||
const outputSchema: any[] = []
|
||||
Object.keys(output_schema.properties).forEach((outputKey) => {
|
||||
const output = output_schema.properties[outputKey]
|
||||
outputSchema.push({
|
||||
variable: outputKey,
|
||||
type: output.type === 'array'
|
||||
? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]`
|
||||
: `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`,
|
||||
description: output.description,
|
||||
})
|
||||
})
|
||||
res.vars = [
|
||||
...TOOL_OUTPUT_STRUCT,
|
||||
...outputSchema,
|
||||
]
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
|
||||
handleRun,
|
||||
handleStop,
|
||||
runResult,
|
||||
outputSchema,
|
||||
} = useConfig(id, data)
|
||||
const toolIcon = useToolIcon(data)
|
||||
const {
|
||||
@ -143,6 +144,14 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
|
||||
type='Array[Object]'
|
||||
description={t(`${i18nPrefix}.outputVars.json`)}
|
||||
/>
|
||||
{outputSchema.map(outputItem => (
|
||||
<VarItem
|
||||
key={outputItem.name}
|
||||
name={outputItem.name}
|
||||
type={outputItem.type}
|
||||
description={outputItem.description}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
</OutputVars>
|
||||
</div>
|
||||
|
@ -20,4 +20,5 @@ export type ToolNodeType = CommonNodeType & {
|
||||
tool_label: string
|
||||
tool_parameters: ToolVarInputs
|
||||
tool_configurations: Record<string, any>
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
@ -29,8 +29,9 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
||||
/*
|
||||
* tool_configurations: tool setting, not dynamic setting
|
||||
* tool_parameters: tool dynamic setting(by user)
|
||||
* output_schema: tool dynamic output
|
||||
*/
|
||||
const { provider_id, provider_type, tool_name, tool_configurations } = inputs
|
||||
const { provider_id, provider_type, tool_name, tool_configurations, output_schema } = inputs
|
||||
const isBuiltIn = provider_type === CollectionType.builtIn
|
||||
const buildInTools = useStore(s => s.buildInTools)
|
||||
const customTools = useStore(s => s.customTools)
|
||||
@ -91,7 +92,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
||||
const value = newConfig[key]
|
||||
if (schema?.type === 'boolean') {
|
||||
if (typeof value === 'string')
|
||||
newConfig[key] = parseInt(value, 10)
|
||||
newConfig[key] = Number.parseInt(value, 10)
|
||||
|
||||
if (typeof value === 'boolean')
|
||||
newConfig[key] = value ? 1 : 0
|
||||
@ -99,7 +100,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
||||
|
||||
if (schema?.type === 'number-input') {
|
||||
if (typeof value === 'string' && value !== '')
|
||||
newConfig[key] = parseFloat(value)
|
||||
newConfig[key] = Number.parseFloat(value)
|
||||
}
|
||||
})
|
||||
draft.tool_configurations = newConfig
|
||||
@ -254,6 +255,23 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
||||
doHandleRun(addMissedVarData)
|
||||
}
|
||||
|
||||
const outputSchema = useMemo(() => {
|
||||
const res: any[] = []
|
||||
if (!output_schema)
|
||||
return []
|
||||
Object.keys(output_schema.properties).forEach((outputKey) => {
|
||||
const output = output_schema.properties[outputKey]
|
||||
res.push({
|
||||
name: outputKey,
|
||||
type: output.type === 'array'
|
||||
? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]`
|
||||
: `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`,
|
||||
description: output.description,
|
||||
})
|
||||
})
|
||||
return res
|
||||
}, [output_schema])
|
||||
|
||||
return {
|
||||
readOnly,
|
||||
inputs,
|
||||
@ -282,6 +300,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
|
||||
handleRun,
|
||||
handleStop,
|
||||
runResult,
|
||||
outputSchema,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user