arkts-sta-playground

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ArkTS-Sta Playground Runner

ArkTS-Sta Playground 运行器

Overview

概述

This skill runs ArkTS-Sta code using the ArkTS-Sta Playground HTTP API, providing fast and reliable code execution without browser automation.
本技能通过ArkTS-Sta Playground HTTP API运行ArkTS-Sta代码,无需浏览器自动化即可提供快速可靠的代码执行能力。

Quick Start

快速开始

Basic Usage

基础用法

Run an ArkTS-Sta file:
bash
python3 scripts/run_playground.py path/to/code.ets
Run code directly as a string:
bash
python3 scripts/run_playground.py --code "let x: number = 42; console.log(x);"
Get JSON output for programmatic parsing:
bash
python3 scripts/run_playground.py --json --code "console.log('Hello');"
运行ArkTS-Sta文件:
bash
python3 scripts/run_playground.py path/to/code.ets
直接运行字符串形式的代码:
bash
python3 scripts/run_playground.py --code "let x: number = 42; console.log(x);"
获取JSON格式输出以便程序化解析:
bash
python3 scripts/run_playground.py --json --code "console.log('Hello');"

Setup Requirements

环境搭建要求

Install Python dependencies:
bash
pip install -r scripts/requirements.txt
Required package:
requests>=2.31.0
安装Python依赖:
bash
pip install -r scripts/requirements.txt
所需依赖包:
requests>=2.31.0

Usage Patterns

使用场景

Pattern 1: Quick Code Testing

场景1:快速代码测试

When testing ArkTS-Sta syntax or verifying code logic:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
  A = 10,
  B = 2.57,
  C = 0x2B7F,
  D = -1.5,
  E = 12
}
"
测试ArkTS-Sta语法或验证代码逻辑时:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
  A = 10,
  B = 2.57,
  C = 0x2B7F,
  D = -1.5,
  E = 12
}
"

Pattern 2: Batch Testing

场景2:批量测试

For testing multiple files:
bash
for file in test/*.ets; do
    python3 scripts/run_playground.py --json "$file" > "results/$(basename $file .ets).json"
done
测试多个文件时:
bash
for file in test/*.ets; do
    python3 scripts/run_playground.py --json "$file" > "results/$(basename $file .ets).json"
done

How It Works

工作原理

The script uses the HTTP API endpoint:
  1. Sends your ArkTS-Sta code to
    https://arkts-play.cn.bz-openlab.ru:10443/compile
  2. Receives compilation results and output
  3. Returns formatted results (success status, output, errors)
该脚本使用以下HTTP API端点:
  1. 将你的ArkTS-Sta代码发送至
    https://arkts-play.cn.bz-openlab.ru:10443/compile
  2. 接收编译结果和输出
  3. 返回格式化后的结果(成功状态、输出内容、错误信息)

API Endpoint

API端点

Base URL:
https://arkts-play.cn.bz-openlab.ru:10443/compile
Method: POST
Request:
json
{
  "code": "your ArkTS-Sta code here"
}
Response:
json
{
  "output": "execution output or empty",
  "error": "error message if compilation failed, null otherwise"
}
基础URL:
https://arkts-play.cn.bz-openlab.ru:10443/compile
请求方法: POST
请求体:
json
{
  "code": "your ArkTS-Sta code here"
}
响应体:
json
{
  "output": "execution output or empty",
  "error": "error message if compilation failed, null otherwise"
}

Troubleshooting

故障排除

Connection issues

连接问题

If you get connection errors:
  1. Check internet connectivity
  2. Verify the API endpoint is accessible
  3. Check firewall settings
bash
undefined
如果遇到连接错误:
  1. 检查网络连接
  2. 验证API端点是否可访问
  3. 检查防火墙设置
bash
undefined

Test connectivity

测试连接

curl -X POST https://arkts-play.cn.bz-openlab.ru:10443/compile
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
undefined
curl -X POST https://arkts-play.cn.bz-openlab.ru:10443/compile
-H "Content-Type: application/json"
-d '{"code":"let x: number = 42;"}'
undefined

Timeout issues

超时问题

Increase timeout if the API is slow:
bash
python3 scripts/run_playground.py --timeout 60 path/to/code.ets
如果API响应缓慢,可增加超时时间:
bash
python3 scripts/run_playground.py --timeout 60 path/to/code.ets

SSL certificate errors

SSL证书错误

If you encounter SSL certificate issues, you may need to:
  • Ensure your system's CA certificates are up to date
  • Or modify the script to disable SSL verification (not recommended for production)
如果遇到SSL证书问题,你可能需要:
  • 确保系统的CA证书是最新的
  • 或者修改脚本以禁用SSL验证(不建议在生产环境中使用)

Common Use Cases

常见使用场景

Learn ArkTS Syntax

学习ArkTS语法

Test and explore ArkTS language features:
bash
python3 scripts/run_playground.py --code "
// Test union types
let value: string | number = 'hello';
value = 42;
console.log(value);
"
测试并探索ArkTS语言特性:
bash
python3 scripts/run_playground.py --code "
// 测试联合类型
let value: string | number = 'hello';
value = 42;
console.log(value);
"

Quick Prototype Verification

快速原型验证

Verify code logic before integrating into your project:
bash
python3 scripts/run_playground.py --code "
function calculateSum(a: number, b: number): number {
    return a + b;
}
console.log('Sum:', calculateSum(10, 20));
"
在集成到项目前验证代码逻辑:
bash
python3 scripts/run_playground.py --code "
function calculateSum(a: number, b: number): number {
    return a + b;
}
console.log('Sum:', calculateSum(10, 20));
"

Debug Code Snippets

调试代码片段

Find compilation errors in your code:
bash
undefined
查找代码中的编译错误:
bash
undefined

Run with JSON output for programmatic checking

以JSON格式输出以便程序化检查

python3 scripts/run_playground.py --json problem.ets
python3 scripts/run_playground.py --json problem.ets

Check exit status

检查退出状态

if python3 scripts/run_playground.py code.ets; then echo "Compilation successful" else echo "Compilation failed" fi
undefined
if python3 scripts/run_playground.py code.ets; then echo "编译成功" else echo "编译失败" fi
undefined

Script Output

脚本输出

The script returns a JSON structure (with
--json
flag):
json
{
  "success": true,
  "output": "Execution result here...",
  "error": null,
  "has_error": false
}
Fields:
  • success
    : Boolean indicating if the API request succeeded
  • output
    : Code output or compilation output
  • error
    : Error message if compilation failed,
    null
    otherwise
  • has_error
    : Boolean indicating if the code has compilation errors
使用
--json
参数时,脚本会返回如下JSON结构:
json
{
  "success": true,
  "output": "Execution result here...",
  "error": null,
  "has_error": false
}
字段说明:
  • success
    :布尔值,表示API请求是否成功
  • output
    :代码输出或编译输出
  • error
    :编译失败时的错误信息,否则为
    null
  • has_error
    :布尔值,表示代码是否存在编译错误

Example: Testing Enum with Floating Point

示例:测试包含浮点数的枚举

Test if enum with non-integer values causes errors:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
  A = 10,
  B = 2.57,
  C = 0x2B7F,
  D = -1.5,
  E = 12
}
"
Expected result: Should fail with an error about enum values needing to be integers.
测试包含非整数值的枚举是否会引发错误:
bash
python3 scripts/run_playground.py --code "
enum Numbers {
  A = 10,
  B = 2.57,
  C = 0x2B7F,
  D = -1.5,
  E = 12
}
"
预期结果:应失败并提示枚举值必须为整数的错误。

Limitations

局限性

  • Requires internet access to the API endpoint
  • API rate limiting may apply
  • Compilation output format depends on the API response
  • 需要联网才能访问API端点
  • API可能存在速率限制
  • 编译输出格式取决于API响应

Tips for Efficient Usage

高效使用技巧

  1. Use JSON output for programmatic processing (
    --json
    )
  2. Batch test multiple files using shell loops
  3. Check exit codes in scripts for success/failure
  1. 使用JSON输出进行程序化处理(
    --json
    参数)
  2. 批量测试多个文件时使用Shell循环
  3. 检查退出码以判断脚本执行成功或失败