fix(agent): include select option labels and field name in autofill schema

This commit is contained in:
yiling
2026-07-28 21:32:47 +08:00
parent 825044f16d
commit 37331eae64
4 changed files with 76 additions and 19 deletions
+40 -3
View File
@@ -9,8 +9,11 @@ describe('fieldsToTypeBoxSchema', () => {
]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('string')
expect(schema.properties.f1.description).toBe('The title')
expect(schema.properties.f1.title).toBe('Title')
expect(schema.properties.f1.description).toBe('Title: The title')
expect(schema.properties.f2.type).toBe('string')
expect(schema.properties.f2.title).toBe('Desc')
expect(schema.properties.f2.description).toBe('Desc')
})
it('converts numeric fields', () => {
@@ -20,21 +23,25 @@ describe('fieldsToTypeBoxSchema', () => {
]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('number')
expect(schema.properties.f1.title).toBe('Price')
expect(schema.properties.f2.type).toBe('number')
expect(schema.properties.f2.title).toBe('Rating')
})
it('converts toggle fields', () => {
const fields: AutofillField[] = [{ id: 'f1', config: { name: 'Active', type: 'toggle' } }]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('boolean')
expect(schema.properties.f1.title).toBe('Active')
})
it('converts select fields with enums', () => {
it('converts select fields with enums and option descriptions', () => {
const fields: AutofillField[] = [
{
id: 'f1',
description: 'Species of animal',
config: {
name: 'Status',
name: 'Species',
type: 'select',
select: {
options: [
@@ -47,7 +54,36 @@ describe('fieldsToTypeBoxSchema', () => {
]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('string')
expect(schema.properties.f1.title).toBe('Species')
expect(schema.properties.f1.enum).toEqual(['opt1', 'opt2'])
expect(schema.properties.f1.description).toBe(
'Species: Species of animal [Allowed options: "opt1" (Option 1), "opt2" (Option 2)]',
)
})
it('converts selectMulti fields with array enums and option descriptions', () => {
const fields: AutofillField[] = [
{
id: 'f1',
config: {
name: 'Tags',
type: 'selectMulti',
selectMulti: {
options: [
{ id: 'opt1', displayName: 'Tag 1', color: 'red' },
{ id: 'opt2', displayName: 'Tag 2', color: 'blue' },
],
},
},
},
]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('array')
expect(schema.properties.f1.title).toBe('Tags')
expect(schema.properties.f1.items.enum).toEqual(['opt1', 'opt2'])
expect(schema.properties.f1.description).toBe(
'Tags [Allowed options: "opt1" (Tag 1), "opt2" (Tag 2)]',
)
})
it('defaults to string for unknown types', () => {
@@ -57,5 +93,6 @@ describe('fieldsToTypeBoxSchema', () => {
]
const schema = fieldsToTypeBoxSchema(fields)
expect(schema.properties.f1.type).toBe('string')
expect(schema.properties.f1.title).toBe('Unknown')
})
})