Feat/sdk targeted list limits (list-limits part of issue #1107) - #34
Open
mbajji wants to merge 2 commits into
Open
Feat/sdk targeted list limits (list-limits part of issue #1107)#34mbajji wants to merge 2 commits into
mbajji wants to merge 2 commits into
Conversation
Contributor
Author
|
@Reemal786 @J-Nad @Alton8 Hi codeDay labs team. Let me know what you think of the changes so far before we hit merge. Feel free to drop any feedback or add your files right in! |
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.
The problem
To change how many items a robot's list collects, you currently have to fetch the robot, dig through its workflow, change one number, and send the entire workflow back, every selector, every field, every pagination setting.
The web app's robot editing page doesn't work that way. It sends just the setting you changed. The SDK should be able to do the same.
What this PR adds
That's it. The request body contains nothing else:
{ "limits": [ { "pairIndex": 0, "actionIndex": 0, "argIndex": 0, "limit": 25 } ] }The three pieces
Robot.setListLimit(limit)— the method most people will use. It looks through the robot's workflow, finds the action that carries a limit, and works out its position for you. You just pass a number.I did it this way because those positions are decided by the server when it processes the workflow, and they change between robots. Asking users to figure tthem out would be asking them to know something they can't reliably know. Throws a clear error if the robot has no such action.
It covers all three robot types that have a limit:
scrapeListcrawlsearchScrape robots store an empty workflow, so they have no limit to set.
Client.updateListLimits(robotId, limits)— the lower-level version, for robots with more than one list, or when you already know the positions.ListLimitUpdate— the type. It matches the shape the web app already sends (src/api/storage.ts:117), so both clients speak the same language.Also added
examples/list-limit.tsand a row in the README examples table.Important: needs the server PR first
This depends on
getmaxun/maxunPR ##1176, which teachesPUT /api/sdk/robots/:idto understandlimits.Without that, this method silently does nothing. The server returns 200 and ignores the field. I confirmed this against Maxun Cloud before writing any code:
So please merge the server PR first, or this looks broken.
How to try it
examples/list-limit.tscreates one robot of each type and prints the stored config before and after each change:The limit moves; everything beside it is identical.
One snag:
examples/package.jsonis stale — it lists@maxun/extractand@maxun/scrape, which no longer exist on npm, sonpm installinsideexamples/fails and themaxun-sdkimport will not resolve. Running from the repo root as above works. Worth fixing separately.What I tested
Against a local server with the other PR's code changes applied in maxun repo:
setListLimit, and again throughupdateListLimitsfieldsandlistSelectoron extract,modeandmaxDepthon crawl,query,providerandmodeon search-1,0,2.5, and bad positions; the stored value didn't movemetaleft the limit aloneValues were read back through
getRobot()after each change, and confirmeddirectly in Postgres rather than trusting the API response: