cameronpcampbell / openblox

An API wrapper for Roblox, written in Typescript. Fully typesafe, optional caching, use any http client.
https://open.blox.wiki
MIT License
23 stars 8 forks source link

[BUG]: `LuauExecutionApi.luauExecutionTask` does not work without `version` being included in the request. #15

Closed LuckFire closed 2 months ago

LuckFire commented 2 months ago

When running this method, the endpoint that is being requested is /cloud/v2/universes/3666294218/places/9938675423/luau-execution-sessions/{session_id}/tasks/{task_id}.

I could be completely wrong, but based on the Open Cloud docs, the endpoint that should be requested is /cloud/v2/universes/{universe}/places/{place}/luau-execution-session-tasks/{task_id}. Unless there is a different method / something I have to do to make it request this endpoint, this seems correct.

Here is the code I am running:

const code = _readLuaFile('classic-shop.luau');
if (!code) return;

let taskId: string;
const { data } = await LuauExecutionApi.executeLuau({
    universeId: 3666294218, placeId: 9938675423,
    script: code
})
taskId = data.path.split('/').slice(-1)[0];

let task;
await poll(LuauExecutionApi.luauExecutionTask, {
    universeId: 3666294218, placeId: 9938675423,
    sessionId: taskId, taskId: taskId,
}, async ({ data }, stop) => {
    console.log(data);
    if (data.state !== 'COMPLETE') {
        setTimeout(() => {}, 1000 * (30 / 5));
    };
    stop();
}).catch((e) => console.log(e, e.response, e.response.body))
LuckFire commented 2 months ago

It seems I'm definitely misunderstanding the use case of this, it definitely isn't some issue with the endpoint path and is something with my logic, still not sure what I'm doing wrong though after debugging and running their Python script since it works.

LuckFire commented 2 months ago

For some weird reason, when I modify my code to be this , it works..

await LuauExecutionApi
    .executeLuau({
        universeId: 3666294218, placeId: 9938675423,
        script
    })
    .then(async ({ data }) => {
        const taskId = data.path.split('/').slice(-1)[0];

        await poll(LuauExecutionApi.luauExecutionTask, {
            universeId: 3666294218, placeId: 9938675423,
            sessionId: taskId, taskId: taskId
        }, async ({ data }, stop) => {
            console.log(data);

            if (data.state !== 'COMPLETE') return;

            stop();
        })
    })
    .catch((e) => console.log(e));

EDIT: Nevermind, just randomly stopped working again! Also, after looking at your docs a bit, I think you accidentally made sessionId required for LuauExecutionApi.luauExecutionTask, seeing how LuauExecutionApi.listLuauExecutionLogs doesn't require it and the endpoint that the method uses has a variation without it.

LuckFire commented 2 months ago

Found out the issue! You have to provide the version, which openblox provides no real way to easily grab that. I was going to request this anyways, but it seems necessary now. This also seems to happen with LuauExecutionApi.listLuauExecutionLogs.

If possible, could you guys add a way to grab the session id, task id, and version that is provided in the path with some sort of util?

EDIT: Another thing, it seems like there's no way to grab the result when the request is completed. You can make a type for where if there state is "COMPELTE", it will include the output (which should be typeset for custom data).

cameronpcampbell commented 2 months ago

The LuauExecution docs are really confusing. It gives 4 different paths for each endpoint - some of which return 404.

EDIT: Another thing, it seems like there's no way to grab the result when the request is completed. You can make a type for where if there state is "COMPELTE", it will include the output (which should be typeset for custom data).

The example for luauExecutionTask has this by setting the task variable to the data once the state is COMPLETE.

LuckFire commented 2 months ago

I was pulling my hair out trying to figure out what I was doing wrong, all it was is version missing 😅 glad but upset at the same time to see this was Roblox's own issue.

The example for luauExecutionTask has this by setting the task variable to the data once the state is COMPLETE.

What I meant was, I cannot do data.output.results because the types aren't provided for it, so the compiler just yells at me when I try to set it to the data. image

cameronpcampbell commented 2 months ago

Oh I see. my apologies for the misunderstanding. I can add a type argument to the luauExecutionTask to allow the results field to be typed which should fix this issue.

LuckFire commented 2 months ago

Awesome, that'd be great

LuckFire commented 2 months ago

Hey, not to rush you guys or anything, any idea on when the type argument may be pushed? If you guys are unavailable I'll happily make a PR adding it

Just need it before I can push code for something so I'm wondering how long it'll be 😅

cameronpcampbell commented 2 months ago

Changes should be merged soon. My apologies for the delay.

cameronpcampbell commented 2 months ago

Changes have now been pushed in v1.0.53. I appreciate your patience 😅.

changelog

changelog (not pertaining to this issue)

LuckFire commented 2 months ago

Awesome! Though I think there's a slight issue with the types for results. It seems like it's typed to only have output, even tho the way it's returned is

{
    "output": {
        "results": []
    }
}

image

EDIT: nevermind, I think it was being weird cause I never set the types! whoops 😅

cameronpcampbell commented 2 months ago

Oh btw heres an updated example of executing luau and then polling for it to complete. You'll be pleased to know that theres no longer any funny business with having that task variable 😅.

const { data:{ universeId, placeId, version, sessionId, taskId } } = await LuauExecutionApi.executeLuau({
  universeId: 5795192361, placeId: 16866553538, script: `local x, y = 3, 4; return x + y`
})

type Results = number[]

const { data:executedTask } = await pollMethod(
  LuauExecutionApi.luauExecutionTask<Results>({ universeId, placeId, version, sessionId, taskId }),
  async ({ data }, stopPolling) => data.state === "COMPLETE" && stopPolling()
)

console.log(!executedTask.error && executedTask.output.results)

If you are running into any other issues regarding the LuauExecution then do be sure to open up a new ticket. 😅

LuckFire commented 2 months ago

Yes I saw, thank you for adding that! Everything is working perfectly now, appreciate your work so much 🙏 genuine life saver

LuckFire commented 1 month ago

Hey, not sure if I should make a separate issue for this or not so I decided to go back to this one where it was originally discussed.

Any plans on removing the console.log where it prints out that it's polling the method? Just a very nit-picky thing since I like to have control over what's being output into my log, if it's necessary maybe put it behind some debug log flag?

image

cameronpcampbell commented 1 month ago

sure, I can make a debug log flag. The main purpose of this particular log was so that people wouldn't think that openblox was infinitely hanging - but yea I can see how this can be annoying.