-
Notifications
You must be signed in to change notification settings - Fork 78
fix: tool schema array type infer and nested props #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
closes #44 |
jirispilka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a bit complicated .... can you please provide more documentation, why we need it? Maybe including examples?
The doc will become handy for developing standalone MCP Serve (at the level of Apify Api)
| export function filterSchemaProperties(properties: { [key: string]: ISchemaProperties }): { [key: string]: ISchemaProperties } { | ||
| const filteredProperties: { [key: string]: ISchemaProperties } = {}; | ||
| for (const [key, property] of Object.entries(properties)) { | ||
| const { title, description, enum: enumValues, type, default: defaultValue, prefill } = property; | ||
| filteredProperties[key] = { title, description, enum: enumValues, type, default: defaultValue, prefill }; | ||
| if (type === 'array') { | ||
| const { title, description, enum: enumValues, type, | ||
| default: defaultValue, prefill, properties: subProperties, | ||
| items, required } = property; | ||
| filteredProperties[key] = { title, | ||
| description, | ||
| enum: enumValues, | ||
| type, | ||
| default: defaultValue, | ||
| prefill, | ||
| properties: subProperties, | ||
| items, | ||
| required }; | ||
| if (type === 'array' && !items?.type) { | ||
| const itemsType = inferArrayItemType(property); | ||
| if (itemsType) { | ||
| filteredProperties[key].items = { type: itemsType }; | ||
| filteredProperties[key].items = { | ||
| ...filteredProperties[key].items, | ||
| title: filteredProperties[key].title ?? 'Item', | ||
| description: filteredProperties[key].description ?? 'Item', | ||
| type: itemsType, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| return filteredProperties; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be nicer like this?
I haven't tested it, only draft.
export function filterSchemaProperties(properties: { [key: string]: ISchemaProperties }): { [key: string]: ISchemaProperties } {
const filteredProperties: { [key: string]: ISchemaProperties } = {};
for (const [key, property] of Object.entries(properties)) {
filteredProperties[key] = {
title: property.title,
description: property.description,
enum: property.enum,
type: property.type,
default: property.default,
prefill: property.prefill,
properties: property.properties,
items: property.items,
required: property.required,
};
if (property.type === 'array' && !property.items?.type) {
const itemsType = inferArrayItemType(property);
if (itemsType) {
filteredProperties[key].items = {
...filteredProperties[key].items,
title: filteredProperties[key].title ?? 'Item',
description: filteredProperties[key].description ?? 'Item',
type: itemsType,
};
}
}
}
return filteredProperties;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jirispilka yes, I haven't refactored the original code, but I think once we have a fully functional version a refactor would be great 👍
jirispilka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. I hope you've tested it with a set of different Actors
Tested with set of different Actors and seems to be working, the only issue currently with mastra.ai agent is the timeout: when tool call takes longer than 60 s it times out. Will check with the mastra.ai guys. |
mastra.ai agent failed to run WCC because of the nested properties, the object input properties: had to infer their schema based on the editor provided; This helps the agent to call the WCC with the correct options.