Skip to content

Commit 653d80a

Browse files
authored
Luau execution impl (#72)
* Luau execution impl * Luau execution client impl * Luau execution CLI stub * Luau execution CLI * Docs * Log query params
1 parent c2f40fd commit 653d80a

File tree

8 files changed

+662
-8
lines changed

8 files changed

+662
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Possible use-cases:
3434
| :white_check_mark: | User Notifications |
3535
| :white_check_mark: | User |
3636
| :x: | Creator Store |
37-
| :x: | Luau Execution |
37+
| :white_check_mark: | Luau Execution |
3838

3939
- :white_check_mark: = Supported
4040
- :x: = Not yet supported

docs/cli/cli-luau-execution.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Luau Execution API
2+
3+
# Execute Task
4+
Executes Luau code on Roblox.
5+
```
6+
Usage: rbxcloud luau execute [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --api-key <API_KEY>
7+
8+
Options:
9+
-u, --universe-id <UNIVERSE_ID> Universe ID of the experience
10+
-i, --place-id <PLACE_ID> Place ID of the experience
11+
-r, --version-id <VERSION_ID> Version ID of the experience
12+
-s, --script <SCRIPT> Script source code
13+
-f, --filepath <FILEPATH> Script source code file
14+
-t, --timeout <TIMEOUT> Execution timeout
15+
-p, --pretty Pretty-print the JSON response
16+
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
17+
-h, --help Print help
18+
```
19+
20+
## Get Task Information
21+
Gets information on a previously executed task.
22+
23+
```
24+
Usage: rbxcloud luau get-task [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --session-id <SESSION_ID> --task-id <TASK_ID> --api-key <API_KEY>
25+
26+
Options:
27+
-u, --universe-id <UNIVERSE_ID> Universe ID of the experience
28+
-i, --place-id <PLACE_ID> Place ID of the experience
29+
-r, --version-id <VERSION_ID> Version ID of the experience
30+
-s, --session-id <SESSION_ID> Luau execution session ID
31+
-t, --task-id <TASK_ID> Luau execution task ID
32+
-p, --pretty Pretty-print the JSON response
33+
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
34+
-h, --help Print help
35+
```
36+
37+
## Get Task Logs
38+
Retrieves logs on a previously executed task.
39+
```
40+
Usage: rbxcloud.exe luau get-logs [OPTIONS] --universe-id <UNIVERSE_ID> --place-id <PLACE_ID> --session-id <SESSION_ID> --task-id <TASK_ID> --api-key <API_KEY>
41+
42+
Options:
43+
-u, --universe-id <UNIVERSE_ID> Universe ID of the experience
44+
-i, --place-id <PLACE_ID> Place ID of the experience
45+
-r, --version-id <VERSION_ID> Version ID of the experience
46+
-s, --session-id <SESSION_ID> Luau execution session ID
47+
-t, --task-id <TASK_ID> Luau execution task ID
48+
-m, --max-page-size <MAX_PAGE_SIZE> Max page size
49+
-n, --page-token <PAGE_TOKEN> Next page token
50+
-w, --view <VIEW> Log view type [possible values: flat, structured]
51+
-p, --pretty Pretty-print the JSON response
52+
-a, --api-key <API_KEY> Roblox Open Cloud API Key [env: RBXCLOUD_API_KEY=]
53+
-h, --help Print help
54+
```

mkdocs.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ nav:
88
- Home: index.md
99
- CLI:
1010
- Install: cli/cli-install.md
11-
- Assets: cli/cli-assets.md
1211
- API Key: cli/cli-api-key.md
13-
- Experience: cli/cli-experience.md
14-
- Messaging: cli/cli-messaging.md
12+
- Assets: cli/cli-assets.md
1513
- DataStore: cli/cli-datastore.md
16-
- OrderedDataStore: cli/cli-ordered-datastore.md
14+
- Experience: cli/cli-experience.md
1715
- Group: cli/cli-group.md
18-
- Subscription: cli/cli-subscription.md
16+
- Luau Execution: cli/cli-luau-execution.md
17+
- Messaging: cli/cli-messaging.md
1918
- Notification: cli/cli-notification.md
19+
- OrderedDataStore: cli/cli-ordered-datastore.md
2020
- Place: cli/cli-place.md
21+
- Subscription: cli/cli-subscription.md
2122
- Universe: cli/cli-universe.md
2223
- User: cli/cli-user.md
2324
- Rust Lib:

src/cli/luau_execution_cli.rs

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
use clap::{Args, Subcommand};
2+
use rbxcloud::rbx::{
3+
types::{PlaceId, UniverseId},
4+
v2::{luau_execution::LuauExecutionTaskLogView, Client},
5+
};
6+
use tokio::fs;
7+
8+
#[derive(Debug, Subcommand)]
9+
pub enum LuauExecutionCommands {
10+
/// Executes Luau code on Roblox
11+
Execute {
12+
/// Universe ID of the experience
13+
#[clap(short, long, value_parser)]
14+
universe_id: u64,
15+
16+
/// Place ID of the experience
17+
#[clap(short = 'i', long, value_parser)]
18+
place_id: u64,
19+
20+
/// Version ID of the experience
21+
#[clap(short = 'r', long, value_parser)]
22+
version_id: Option<String>,
23+
24+
/// Script source code
25+
#[clap(short, long, value_parser)]
26+
script: Option<String>,
27+
28+
/// Script source code file
29+
#[clap(short, long, value_parser)]
30+
filepath: Option<String>,
31+
32+
/// Execution timeout
33+
#[clap(short, long, value_parser)]
34+
timeout: Option<String>,
35+
36+
/// Pretty-print the JSON response
37+
#[clap(short, long, value_parser, default_value_t = false)]
38+
pretty: bool,
39+
40+
/// Roblox Open Cloud API Key
41+
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
42+
api_key: String,
43+
},
44+
45+
/// Gets information on a previously executed task
46+
GetTask {
47+
/// Universe ID of the experience
48+
#[clap(short, long, value_parser)]
49+
universe_id: u64,
50+
51+
/// Place ID of the experience
52+
#[clap(short = 'i', long, value_parser)]
53+
place_id: u64,
54+
55+
/// Version ID of the experience
56+
#[clap(short = 'r', long, value_parser)]
57+
version_id: Option<String>,
58+
59+
/// Luau execution session ID
60+
#[clap(short, long, value_parser)]
61+
session_id: String,
62+
63+
/// Luau execution task ID
64+
#[clap(short, long, value_parser)]
65+
task_id: String,
66+
67+
/// Pretty-print the JSON response
68+
#[clap(short, long, value_parser, default_value_t = false)]
69+
pretty: bool,
70+
71+
/// Roblox Open Cloud API Key
72+
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
73+
api_key: String,
74+
},
75+
76+
/// Retrieves logs on a previously executed task
77+
GetLogs {
78+
/// Universe ID of the experience
79+
#[clap(short, long, value_parser)]
80+
universe_id: u64,
81+
82+
/// Place ID of the experience
83+
#[clap(short = 'i', long, value_parser)]
84+
place_id: u64,
85+
86+
/// Version ID of the experience
87+
#[clap(short = 'r', long, value_parser)]
88+
version_id: Option<String>,
89+
90+
/// Luau execution session ID
91+
#[clap(short, long, value_parser)]
92+
session_id: String,
93+
94+
/// Luau execution task ID
95+
#[clap(short, long, value_parser)]
96+
task_id: String,
97+
98+
/// Max page size
99+
#[clap(short, long, value_parser)]
100+
max_page_size: Option<u32>,
101+
102+
/// Next page token
103+
#[clap(short = 'n', long, value_parser)]
104+
page_token: Option<String>,
105+
106+
/// Log view type
107+
#[clap(short = 'w', long, value_enum)]
108+
view: Option<LuauExecutionTaskLogView>,
109+
110+
/// Pretty-print the JSON response
111+
#[clap(short, long, value_parser, default_value_t = false)]
112+
pretty: bool,
113+
114+
/// Roblox Open Cloud API Key
115+
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
116+
api_key: String,
117+
},
118+
}
119+
120+
#[derive(Debug, Args)]
121+
pub struct Luau {
122+
#[clap(subcommand)]
123+
command: LuauExecutionCommands,
124+
}
125+
126+
impl Luau {
127+
pub async fn run(self) -> anyhow::Result<Option<String>> {
128+
match self.command {
129+
LuauExecutionCommands::Execute {
130+
universe_id,
131+
place_id,
132+
version_id,
133+
script,
134+
filepath,
135+
timeout,
136+
pretty,
137+
api_key,
138+
} => {
139+
let client = Client::new(&api_key);
140+
141+
let luau = client.luau(UniverseId(universe_id), PlaceId(place_id), version_id);
142+
143+
let mut script_source: Option<String> = None;
144+
if script.is_some() {
145+
script_source = script;
146+
}
147+
148+
if script_source.is_none() {
149+
if let Some(path) = filepath {
150+
let src_bytes = fs::read(path).await?;
151+
script_source = Some(String::from_utf8(src_bytes)?);
152+
}
153+
}
154+
155+
let src = script_source.expect("script or filepath must be set");
156+
157+
let res = luau.create_task(src, timeout).await;
158+
match res {
159+
Ok(data) => {
160+
let r = if pretty {
161+
serde_json::to_string_pretty(&data)?
162+
} else {
163+
serde_json::to_string(&data)?
164+
};
165+
Ok(Some(r))
166+
}
167+
Err(err) => Err(anyhow::anyhow!(err)),
168+
}
169+
}
170+
171+
LuauExecutionCommands::GetTask {
172+
universe_id,
173+
place_id,
174+
version_id,
175+
session_id,
176+
task_id,
177+
pretty,
178+
api_key,
179+
} => {
180+
let client = Client::new(&api_key);
181+
182+
let luau = client.luau(UniverseId(universe_id), PlaceId(place_id), version_id);
183+
184+
let res = luau.get_task(session_id, task_id).await;
185+
match res {
186+
Ok(data) => {
187+
let r = if pretty {
188+
serde_json::to_string_pretty(&data)?
189+
} else {
190+
serde_json::to_string(&data)?
191+
};
192+
Ok(Some(r))
193+
}
194+
Err(err) => Err(anyhow::anyhow!(err)),
195+
}
196+
}
197+
198+
LuauExecutionCommands::GetLogs {
199+
universe_id,
200+
place_id,
201+
version_id,
202+
session_id,
203+
task_id,
204+
max_page_size,
205+
page_token,
206+
view,
207+
pretty,
208+
api_key,
209+
} => {
210+
let client = Client::new(&api_key);
211+
212+
let luau = client.luau(UniverseId(universe_id), PlaceId(place_id), version_id);
213+
214+
let res = luau
215+
.get_logs(
216+
session_id,
217+
task_id,
218+
view.unwrap_or(LuauExecutionTaskLogView::Flat),
219+
max_page_size,
220+
page_token,
221+
)
222+
.await;
223+
match res {
224+
Ok(data) => {
225+
let r = if pretty {
226+
serde_json::to_string_pretty(&data)?
227+
} else {
228+
serde_json::to_string(&data)?
229+
};
230+
Ok(Some(r))
231+
}
232+
Err(err) => Err(anyhow::anyhow!(err)),
233+
}
234+
}
235+
}
236+
}
237+
}

src/cli/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod assets_cli;
22
mod datastore_cli;
33
mod experience_cli;
44
mod group_cli;
5+
mod luau_execution_cli;
56
mod messaging_cli;
67
mod notification_cli;
78
mod ordered_datastore_cli;
@@ -11,6 +12,7 @@ mod universe_cli;
1112
mod user_cli;
1213

1314
use clap::{Parser, Subcommand};
15+
use luau_execution_cli::Luau;
1416
use universe_cli::Universe;
1517
use user_cli::User;
1618

@@ -47,6 +49,8 @@ pub enum Command {
4749
/// Access the Roblox Group API
4850
Group(Group),
4951

52+
Luau(Luau),
53+
5054
/// Access the Roblox Subscription API
5155
Subscription(Subscription),
5256

@@ -72,6 +76,7 @@ impl Cli {
7276
Command::Datastore(command) => command.run().await,
7377
Command::OrderedDatastore(command) => command.run().await,
7478
Command::Group(command) => command.run().await,
79+
Command::Luau(command) => command.run().await,
7580
Command::Subscription(command) => command.run().await,
7681
Command::Notification(command) => command.run().await,
7782
Command::Place(command) => command.run().await,

src/rbx/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use serde::{Deserialize, Serialize};
2+
13
/// Represents the UniverseId of a Roblox experience.
2-
#[derive(Debug, Clone, Copy)]
4+
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
35
pub struct UniverseId(pub u64);
46

57
/// Represents the PlaceId of a specific place within a Roblox experience.
6-
#[derive(Debug, Clone, Copy)]
8+
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
79
pub struct PlaceId(pub u64);
810

911
// Number of items to return.

0 commit comments

Comments
 (0)