mirror of
https://github.com/langgenius/dify.git
synced 2026-04-10 12:00:26 -04:00
fix(web): resolve Dify compact array types in tool output schema (#34804)
This commit is contained in:
@@ -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' })
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user