mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 21:29:22 +00:00
fix(agent): remove title property options from autofill schema for maximum provider compatibility
This commit is contained in:
@@ -409,6 +409,7 @@ export interface AutofillAiParams {
|
||||
export async function autofillAiActivity(params: AutofillAiParams) {
|
||||
const prompt = 'Analyze the provided images and extract metadata.'
|
||||
const toolSchema = fieldsToTypeBoxSchema(params.fields)
|
||||
console.log('==== autofill schema', toolSchema)
|
||||
let capturedData: Record<string, unknown> | null = null
|
||||
|
||||
const autofillTool: AgentTool = {
|
||||
|
||||
@@ -324,19 +324,18 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) {
|
||||
switch (f.config.type) {
|
||||
case 'text':
|
||||
case 'longText':
|
||||
schema = Type.String({ title: fieldName })
|
||||
schema = Type.String()
|
||||
break
|
||||
case 'number':
|
||||
case 'rating':
|
||||
schema = Type.Number({ title: fieldName })
|
||||
schema = Type.Number()
|
||||
break
|
||||
case 'toggle':
|
||||
schema = Type.Boolean({ title: fieldName })
|
||||
schema = Type.Boolean()
|
||||
break
|
||||
case 'select': {
|
||||
const options = f.config.select?.options || []
|
||||
schema = Type.String({
|
||||
title: fieldName,
|
||||
enum: options.map((o) => o.id),
|
||||
})
|
||||
if (options.length > 0) {
|
||||
@@ -353,7 +352,6 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) {
|
||||
Type.String({
|
||||
enum: options.map((o) => o.id),
|
||||
}),
|
||||
{ title: fieldName },
|
||||
)
|
||||
if (options.length > 0) {
|
||||
const optionMapStr = options.map((o) => `"${o.id}" (${o.displayName})`).join(', ')
|
||||
@@ -364,7 +362,7 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) {
|
||||
break
|
||||
}
|
||||
default:
|
||||
schema = Type.String({ title: fieldName })
|
||||
schema = Type.String()
|
||||
}
|
||||
|
||||
if (!schema.description) {
|
||||
|
||||
@@ -9,10 +9,8 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('string')
|
||||
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')
|
||||
})
|
||||
|
||||
@@ -23,16 +21,13 @@ 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 and option descriptions', () => {
|
||||
@@ -54,7 +49,6 @@ 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)]',
|
||||
@@ -79,7 +73,6 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
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)]',
|
||||
@@ -93,6 +86,5 @@ describe('fieldsToTypeBoxSchema', () => {
|
||||
]
|
||||
const schema = fieldsToTypeBoxSchema(fields)
|
||||
expect(schema.properties.f1.type).toBe('string')
|
||||
expect(schema.properties.f1.title).toBe('Unknown')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user