Skip to content

Commit 6559751

Browse files
authored
fix: update the parameter handling by adding auto-correction for nested fields in request body (#131)
This is kind of a hack, as it doesn't actually fix the generated schema - BUT it _should_ work. My theory is that some agents might get confused with body in body, and this solves that problem.
1 parent 1e29081 commit 6559751

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/graph-tools.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,25 @@ export function registerGraphTools(
192192
break;
193193

194194
case 'Body':
195-
body = paramValue;
195+
if (paramDef.schema) {
196+
const parseResult = paramDef.schema.safeParse(paramValue);
197+
if (!parseResult.success) {
198+
const wrapped = { [paramName]: paramValue };
199+
const wrappedResult = paramDef.schema.safeParse(wrapped);
200+
if (wrappedResult.success) {
201+
logger.info(
202+
`Auto-corrected parameter '${paramName}': AI passed nested field directly, wrapped it as {${paramName}: ...}`
203+
);
204+
body = wrapped;
205+
} else {
206+
body = paramValue;
207+
}
208+
} else {
209+
body = paramValue;
210+
}
211+
} else {
212+
body = paramValue;
213+
}
196214
break;
197215

198216
case 'Header':

0 commit comments

Comments
 (0)