Parcourir la source

fix the dynamic action schema

alexchenzl il y a 5 mois
Parent
commit
10fe38d287

+ 2 - 2
chrome-extension/src/background/agent/actions/builder.ts

@@ -91,12 +91,12 @@ export function buildDynamicActionSchema(actions: Action[]): z.ZodType {
   for (const action of actions) {
     // create a schema for the action, it could be action.schema.schema or null
     // but don't use default: null as it causes issues with Google Generative AI
-    const actionSchema = action.schema.schema.nullable();
+    const actionSchema = action.schema.schema.nullable().describe(action.schema.description);
     schema = schema.extend({
       [action.name()]: actionSchema,
     });
   }
-  return schema.partial().nullable();
+  return schema.partial();
 }
 
 export class ActionBuilder {

+ 4 - 4
chrome-extension/src/background/agent/actions/schemas.ts

@@ -43,7 +43,7 @@ export const clickElementActionSchema: ActionSchema = {
   schema: z.object({
     desc: z.string().optional(), // some small LLM can not generate a description, so let it be optional (but it's still makred as required in json schema)
     index: z.number(),
-    xpath: z.string().optional().nullable(),
+    xpath: z.string().nullable().optional(),
   }),
 };
 
@@ -54,7 +54,7 @@ export const inputTextActionSchema: ActionSchema = {
     desc: z.string().optional(),
     index: z.number(),
     text: z.string(),
-    xpath: z.string().optional().nullable(),
+    xpath: z.string().nullable().optional(),
   }),
 };
 
@@ -99,7 +99,7 @@ export const scrollDownActionSchema: ActionSchema = {
   description: 'Scroll down the page by pixel amount - if no amount is specified, scroll down one page',
   schema: z.object({
     desc: z.string().optional(),
-    amount: z.number().optional().nullable(),
+    amount: z.number().nullable().optional(),
   }),
 };
 
@@ -108,7 +108,7 @@ export const scrollUpActionSchema: ActionSchema = {
   description: 'Scroll up the page by pixel amount - if no amount is specified, scroll up one page',
   schema: z.object({
     desc: z.string().optional(),
-    amount: z.number().optional().nullable(),
+    amount: z.number().nullable().optional(),
   }),
 };