diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index 28ff9d2b..4740676e 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -321,6 +321,7 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) { for (const f of fields) { let schema: TSchema const fieldName = f.config.name + const fieldDesc = f.description || fieldName switch (f.config.type) { case 'text': case 'longText': @@ -339,10 +340,8 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) { enum: options.map((o) => o.id), }) if (options.length > 0) { - const optionMapStr = options.map((o) => `"${o.id}" (${o.displayName})`).join(', ') - const optionDesc = `[Allowed options: ${optionMapStr}]` - const baseDesc = f.description ? `${fieldName}: ${f.description}` : fieldName - schema.description = `${baseDesc} ${optionDesc}` + const optionLines = options.map((o) => `- ${o.displayName} => ${o.id}`).join('\n') + schema.description = `The field '${fieldName}' represents ${fieldDesc}.\nSelect one option and return the option ID as the value.\n\nAvailable options:\n${optionLines}` } break } @@ -354,10 +353,8 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) { }), ) if (options.length > 0) { - const optionMapStr = options.map((o) => `"${o.id}" (${o.displayName})`).join(', ') - const optionDesc = `[Allowed options: ${optionMapStr}]` - const baseDesc = f.description ? `${fieldName}: ${f.description}` : fieldName - schema.description = `${baseDesc} ${optionDesc}` + const optionLines = options.map((o) => `- ${o.displayName} => ${o.id}`).join('\n') + schema.description = `The field '${fieldName}' represents ${fieldDesc}.\nSelect applicable options and return the option IDs as the value.\n\nAvailable options:\n${optionLines}` } break } @@ -366,7 +363,7 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) { } if (!schema.description) { - schema.description = f.description ? `${fieldName}: ${f.description}` : fieldName + schema.description = `The field '${fieldName}' represents ${fieldDesc}.` } properties[f.id] = schema } diff --git a/packages/agent/src/schema-conversion.test.ts b/packages/agent/src/schema-conversion.test.ts index 320ec323..9a101659 100644 --- a/packages/agent/src/schema-conversion.test.ts +++ b/packages/agent/src/schema-conversion.test.ts @@ -9,9 +9,9 @@ describe('fieldsToTypeBoxSchema', () => { ] const schema = fieldsToTypeBoxSchema(fields) expect(schema.properties.f1.type).toBe('string') - expect(schema.properties.f1.description).toBe('Title: The title') + expect(schema.properties.f1.description).toBe("The field 'Title' represents The title.") expect(schema.properties.f2.type).toBe('string') - expect(schema.properties.f2.description).toBe('Desc') + expect(schema.properties.f2.description).toBe("The field 'Desc' represents Desc.") }) it('converts numeric fields', () => { @@ -51,7 +51,7 @@ describe('fieldsToTypeBoxSchema', () => { expect(schema.properties.f1.type).toBe('string') 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)]', + "The field 'Species' represents Species of animal.\nSelect one option and return the option ID as the value.\n\nAvailable options:\n- Option 1 => opt1\n- Option 2 => opt2", ) }) @@ -75,7 +75,7 @@ describe('fieldsToTypeBoxSchema', () => { expect(schema.properties.f1.type).toBe('array') expect(schema.properties.f1.items.enum).toEqual(['opt1', 'opt2']) expect(schema.properties.f1.description).toBe( - 'Tags [Allowed options: "opt1" (Tag 1), "opt2" (Tag 2)]', + "The field 'Tags' represents Tags.\nSelect applicable options and return the option IDs as the value.\n\nAvailable options:\n- Tag 1 => opt1\n- Tag 2 => opt2", ) })