fix(web): resolve Dify compact array types in tool output schema (#34804)

This commit is contained in:
平衡世界的BOY
2026-04-09 16:01:23 +08:00
committed by GitHub
parent d1e33ba9ea
commit 1befd2a602
2 changed files with 47 additions and 0 deletions

View File

@@ -229,6 +229,23 @@ describe('output-schema-utils', () => {
})
})
describe('Dify compact types (workflow-as-tool output_schema)', () => {
it('should resolve array[string] to arrayString (issue #34428)', () => {
const result = resolveVarType({ type: 'array[string]' })
expect(result.type).toBe(VarType.arrayString)
})
it('should resolve Array[string] case-insensitively', () => {
const result = resolveVarType({ type: 'Array[string]' })
expect(result.type).toBe(VarType.arrayString)
})
it('should resolve array[object] to arrayObject', () => {
const result = resolveVarType({ type: 'array[object]' })
expect(result.type).toBe(VarType.arrayObject)
})
})
describe('unknown types', () => {
it('should resolve unknown type to any', () => {
const result = resolveVarType({ type: 'unknown_type' })

View File

@@ -2,6 +2,30 @@ import type { SchemaTypeDefinition } from '@/service/use-common'
import { VarType } from '@/app/components/workflow/types'
import { getMatchedSchemaType } from '../_base/components/variable/use-match-schema-type'
/**
* Workflow-as-tool and some internal APIs store Dify VarType strings (e.g. `array[string]`)
* in JSON Schema `type` instead of standard `{ type: 'array', items: { type: 'string' } }`.
* Map those compact strings to VarType so downstream (e.g. Code node var picker) does not
* fall back to `any` and get filtered out.
*/
const resolveDifyCompactTypeString = (typeStr: string): VarType | undefined => {
const trimmed = typeStr.trim()
const m = /^array\[(string|number|integer|boolean|object|file|any)\]$/i.exec(trimmed)
if (!m)
return undefined
const inner = m[1].toLowerCase()
const map: Record<string, VarType> = {
string: VarType.arrayString,
number: VarType.arrayNumber,
integer: VarType.arrayNumber,
boolean: VarType.arrayBoolean,
object: VarType.arrayObject,
file: VarType.arrayFile,
any: VarType.arrayAny,
}
return map[inner]
}
/**
* Normalizes a JSON Schema type to a simple string type.
* Handles complex schemas with oneOf, anyOf, allOf.
@@ -54,6 +78,12 @@ export const resolveVarType = (
schemaTypeDefinitions?: SchemaTypeDefinition[],
): { type: VarType, schemaType?: string } => {
const schemaType = getMatchedSchemaType(schema, schemaTypeDefinitions)
if (schema && typeof schema.type === 'string') {
const compact = resolveDifyCompactTypeString(schema.type)
if (compact !== undefined)
return { type: compact, schemaType }
}
const normalizedType = normalizeJsonSchemaType(schema)
switch (normalizedType) {