Repository navigation
feat(engine): count on list tools so a Builder If can test "Number of events > 0" (#264) - #265
Merged
Merged
Conversation
A Builder If compares one value and Mastra validates its path against the step's output schema, where an array has no length. withCount wraps a createTool config: count in the output schema, filled after execute. Wraps the config because Tool converts outputSchema in its constructor. Tests: typecheck passes (helper unit tests land with the next commit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
Calendar events and free slots, Gmail/Outlook/Mind mail, payments, quotes, Sheets, Drive, Slack, Notion search and rows, Zoom meetings. test/counted.test.ts fails for any registry tool with a top-level array and no count (one-item and write results are listed as exceptions). Tests: typecheck; test:unit 172/172. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
events.length is refused by Mastra's validator; count > 0 on the sample calendar takes the then way. Tests: bun run test 309/309; k6 count-If 5 VUs 30s 4103 runs, 0 failed, p95 82 ms; load/workflow.js 19338 checks, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
Contributor
Author
|
Merged, so it deploys to the hosted demo after main's CI (rule 3). @AncungAulia the FE part of #264 is yours:
@Lin1er no backend change is needed; the field only appears in tool outputs. |
Contributor
|
Live on the hosted demo:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Engine part of #264. The FE part (offering the fields in the If editor) is for @AncungAulia.
What
withCount(field, config)(engine/src/counted.ts) addscount: numberto a tool's output schema and fills it from the list length afterexecute.googlecalendar_list_eventseventsgooglesheets_read_rangevaluesgooglecalendar_find_free_timeslotsgoogledrive_find_filesfilesgmail_list_emails,outlook_list_emailsemailsslack_list_channelschannelsmail_listmessagesnotion_searchresultslist_paymentspaymentsnotion_query_databaserowsget_quotesquoteszoom_list_meetingsmeetingsgooglesheets_find_spreadsheetsspreadsheets{ left: "{{steps.<node>.count}}", op: "gt", right: 0 }.{{steps.<node>.events.length}}is still refused (400 invalid_workflow, Mastra'sinvalid-predicate-reference).If on an Ask reply (
{{steps.<agent>.text}})eq/ne,in/notIn, no contains or ignore-case).Yes, soeq "yes"took the else way.Tests (local)
bun run typecheck: passes.bun run test:unit: 172/172.test/counted.test.tsfails for any registry tool with a top-level array and nocount.bun run test, real NEAR AI plus local Postgres: 309/309. New case intest/workflows.test.ts:events.lengthrefused;count > 0on the sample calendar takes the then way.countwith the demo calendar, 5 VUs for 30 s: 4103 runs, 0 failed, every run took the then way, p95 82 ms.load/workflow.js: 19338 checks, 0 failed.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e