luaskills-sdk 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ recursive-include examples *.py
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: luaskills-sdk
3
+ Version: 0.2.3
4
+ Summary: Python SDK for integrating the LuaSkills runtime through the public JSON FFI surface.
5
+ Author: LuaSkills
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/LuaSkills/luaskills
8
+ Keywords: lua,skills,ffi,runtime,sdk
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+
19
+ # luaskills-sdk
20
+
21
+ Python SDK,用于通过公共 `_json` FFI 集成 LuaSkills 运行时。
22
+
23
+ SDK 封装了动态库加载、`FfiBorrowedBuffer` / `FfiOwnedBuffer`、JSON 包络、engine 生命周期、root helper、authority、skill-config、普通管理面与 system 管理面。宿主不需要在业务代码中重复手写 ctypes buffer。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install luaskills-sdk
29
+ ```
30
+
31
+ 当前包不内置 `luaskills` 原生动态库。调用时需要通过 `library_path` 或 `LUASKILLS_LIB` 指向动态库:
32
+
33
+ ```powershell
34
+ $env:LUASKILLS_LIB = "D:\path\to\luaskills.dll"
35
+ ```
36
+
37
+ ## 基础用法
38
+
39
+ ```python
40
+ from luaskills import Authority, LuaSkillsClient, RuntimeRoots
41
+
42
+ runtime_root = "D:/runtime/luaskills"
43
+ roots = RuntimeRoots.standard(runtime_root)
44
+
45
+ with LuaSkillsClient(library_path="D:/path/to/luaskills.dll", runtime_root=runtime_root) as client:
46
+ client.load_from_roots(roots)
47
+ entries = client.list_entries(Authority.DELEGATED_TOOL)
48
+ result = client.call_skill("demo-standard-ffi-skill-ping", {"note": "python-sdk"})
49
+
50
+ print(entries)
51
+ print(result["content"])
52
+ ```
53
+
54
+ ## CLI
55
+
56
+ 安装后可使用:
57
+
58
+ ```bash
59
+ luaskills install-runtime --database vldb-controller --runtime-root D:\runtime\luaskills
60
+ luaskills install-runtime --database vldb-direct --runtime-root D:\runtime\luaskills
61
+ luaskills install-runtime --database none --runtime-root D:\runtime\luaskills
62
+ luaskills version --lib D:\path\to\luaskills.dll
63
+ luaskills list --lib D:\path\to\luaskills.dll --runtime-root D:\runtime\luaskills
64
+ luaskills call demo-standard-ffi-skill-ping "{\"note\":\"python\"}" --lib D:\path\to\luaskills.dll
65
+ ```
66
+
67
+ `install-runtime` 会按当前平台下载并安装 Lua runtime、LuaSkills FFI 与可选数据库资产,并写入 `resources/luaskills-sdk-runtime-manifest.json`:
68
+
69
+ - `none`:安装 `lua-runtime-{platform}.tar.gz` 与 LuaSkills FFI SDK 资产,不安装数据库 provider。
70
+ - `vldb-controller`:下载 `vldb-controller-{version}-{target}`,用于 `space_controller` provider mode。
71
+ - `vldb-direct`:下载 `vldb-sqlite-lib-{version}-{target}` 与 `vldb-lancedb-lib-{version}-{target}`,用于 `dynamic_library` provider mode。
72
+ - `host-callback`:不下载 VLDB 资产,生成 `host_callback + json` 的 host option patch。
73
+
74
+ `lua-runtime-{platform}.tar.gz` 默认安装 `lua_packages`、运行时 `libs`、`resources` 与授权材料。如果宿主已经自行管理 Lua runtime,可使用 `--skip-lua-runtime` 跳过。
75
+
76
+ 排查发布资产名时可先使用:
77
+
78
+ ```bash
79
+ luaskills install-runtime --database vldb-direct --dry-run
80
+ luaskills install-runtime --database none --skip-lua-runtime --dry-run
81
+ ```
82
+
83
+ 安装完成后,`LuaSkillsClient(runtime_root=...)` 会自动从 `runtime_root/libs` 解析 LuaSkills 动态库,并读取该 manifest 把数据库 provider 的 host option patch 合入默认配置;宿主仍可通过显式 `library_path` 与 `host_options` 覆盖。
84
+
85
+ 管理命令示例:
86
+
87
+ ```bash
88
+ luaskills install LuaSkills/luaskills-demo-skill --target-root USER
89
+ luaskills update LuaSkills/luaskills-demo-skill --target-root USER
90
+ luaskills uninstall luaskills-demo-skill --target-root USER
91
+ ```
92
+
93
+ system 管理入口必须由宿主决定 authority:
94
+
95
+ ```bash
96
+ luaskills system-install LuaSkills/luaskills-demo-skill --target-root ROOT --authority system
97
+ ```
98
+
99
+ 如果 system 工具封装给普通 tools,应固定使用 `--authority delegated_tool`。
100
+
101
+ ## JSON Provider Callback
102
+
103
+ SQLite / LanceDB 的 `host_callback + json` 模式可以直接通过 SDK 注册,宿主无需在业务代码中重复手写 ctypes buffer:
104
+
105
+ ```python
106
+ from luaskills import LuaSkillsClient, LuaSkillsJsonFfi
107
+
108
+ ffi = LuaSkillsJsonFfi("D:/path/to/luaskills.dll")
109
+
110
+
111
+ def sqlite_provider(request):
112
+ return {"ok": True, "request": request}
113
+
114
+
115
+ ffi.set_sqlite_provider_json_callback(sqlite_provider)
116
+
117
+ try:
118
+ client = LuaSkillsClient(
119
+ library_path="D:/path/to/luaskills.dll",
120
+ runtime_root="D:/runtime/luaskills",
121
+ host_options={
122
+ "sqlite_provider_mode": "host_callback",
123
+ "sqlite_callback_mode": "json",
124
+ },
125
+ )
126
+ client.close()
127
+ finally:
128
+ ffi.clear_sqlite_provider_json_callback()
129
+ ```
130
+
131
+ callback 必须在 `engine_new` 前注册;engine 创建后再切换 callback 不会 retroactive 影响已存在 engine。
132
+
133
+ pip 安装后的 wheel 内置可运行示例:
134
+
135
+ ```bash
136
+ python -m luaskills.examples.basic
137
+ python -m luaskills.examples.provider_callback
138
+ ```
139
+
140
+ 源码仓库中同样保留 `examples/basic.py` 与 `examples/provider_callback.py`,便于直接阅读。
141
+
142
+ ## 权限与边界
143
+
144
+ - 查询类接口默认使用 `DelegatedTool`,因此不会返回 `ROOT` skills。
145
+ - `System` 只表示可管理 ROOT 层,不表示可绕过 ROOT 同名占用规则。
146
+ - `call_skill` 与 `run_lua` 是运行时执行面,不作为 ROOT 可见性过滤。
147
+ - skill-config 按 `skill_id + key` 读写,只有 Lua skill 实际读取配置时才影响行为。
148
+ - 如果宿主不希望用户执行任意 Lua,不应直接暴露 `run_lua`。
149
+
150
+ ## 验证
151
+
152
+ 源码环境可运行:
153
+
154
+ ```bash
155
+ python -m compileall sdk/python/src
156
+ PYTHONPATH=sdk/python/src python -m luaskills.cli version --lib target/debug/luaskills.dll
157
+ ```
@@ -0,0 +1,139 @@
1
+ # luaskills-sdk
2
+
3
+ Python SDK,用于通过公共 `_json` FFI 集成 LuaSkills 运行时。
4
+
5
+ SDK 封装了动态库加载、`FfiBorrowedBuffer` / `FfiOwnedBuffer`、JSON 包络、engine 生命周期、root helper、authority、skill-config、普通管理面与 system 管理面。宿主不需要在业务代码中重复手写 ctypes buffer。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pip install luaskills-sdk
11
+ ```
12
+
13
+ 当前包不内置 `luaskills` 原生动态库。调用时需要通过 `library_path` 或 `LUASKILLS_LIB` 指向动态库:
14
+
15
+ ```powershell
16
+ $env:LUASKILLS_LIB = "D:\path\to\luaskills.dll"
17
+ ```
18
+
19
+ ## 基础用法
20
+
21
+ ```python
22
+ from luaskills import Authority, LuaSkillsClient, RuntimeRoots
23
+
24
+ runtime_root = "D:/runtime/luaskills"
25
+ roots = RuntimeRoots.standard(runtime_root)
26
+
27
+ with LuaSkillsClient(library_path="D:/path/to/luaskills.dll", runtime_root=runtime_root) as client:
28
+ client.load_from_roots(roots)
29
+ entries = client.list_entries(Authority.DELEGATED_TOOL)
30
+ result = client.call_skill("demo-standard-ffi-skill-ping", {"note": "python-sdk"})
31
+
32
+ print(entries)
33
+ print(result["content"])
34
+ ```
35
+
36
+ ## CLI
37
+
38
+ 安装后可使用:
39
+
40
+ ```bash
41
+ luaskills install-runtime --database vldb-controller --runtime-root D:\runtime\luaskills
42
+ luaskills install-runtime --database vldb-direct --runtime-root D:\runtime\luaskills
43
+ luaskills install-runtime --database none --runtime-root D:\runtime\luaskills
44
+ luaskills version --lib D:\path\to\luaskills.dll
45
+ luaskills list --lib D:\path\to\luaskills.dll --runtime-root D:\runtime\luaskills
46
+ luaskills call demo-standard-ffi-skill-ping "{\"note\":\"python\"}" --lib D:\path\to\luaskills.dll
47
+ ```
48
+
49
+ `install-runtime` 会按当前平台下载并安装 Lua runtime、LuaSkills FFI 与可选数据库资产,并写入 `resources/luaskills-sdk-runtime-manifest.json`:
50
+
51
+ - `none`:安装 `lua-runtime-{platform}.tar.gz` 与 LuaSkills FFI SDK 资产,不安装数据库 provider。
52
+ - `vldb-controller`:下载 `vldb-controller-{version}-{target}`,用于 `space_controller` provider mode。
53
+ - `vldb-direct`:下载 `vldb-sqlite-lib-{version}-{target}` 与 `vldb-lancedb-lib-{version}-{target}`,用于 `dynamic_library` provider mode。
54
+ - `host-callback`:不下载 VLDB 资产,生成 `host_callback + json` 的 host option patch。
55
+
56
+ `lua-runtime-{platform}.tar.gz` 默认安装 `lua_packages`、运行时 `libs`、`resources` 与授权材料。如果宿主已经自行管理 Lua runtime,可使用 `--skip-lua-runtime` 跳过。
57
+
58
+ 排查发布资产名时可先使用:
59
+
60
+ ```bash
61
+ luaskills install-runtime --database vldb-direct --dry-run
62
+ luaskills install-runtime --database none --skip-lua-runtime --dry-run
63
+ ```
64
+
65
+ 安装完成后,`LuaSkillsClient(runtime_root=...)` 会自动从 `runtime_root/libs` 解析 LuaSkills 动态库,并读取该 manifest 把数据库 provider 的 host option patch 合入默认配置;宿主仍可通过显式 `library_path` 与 `host_options` 覆盖。
66
+
67
+ 管理命令示例:
68
+
69
+ ```bash
70
+ luaskills install LuaSkills/luaskills-demo-skill --target-root USER
71
+ luaskills update LuaSkills/luaskills-demo-skill --target-root USER
72
+ luaskills uninstall luaskills-demo-skill --target-root USER
73
+ ```
74
+
75
+ system 管理入口必须由宿主决定 authority:
76
+
77
+ ```bash
78
+ luaskills system-install LuaSkills/luaskills-demo-skill --target-root ROOT --authority system
79
+ ```
80
+
81
+ 如果 system 工具封装给普通 tools,应固定使用 `--authority delegated_tool`。
82
+
83
+ ## JSON Provider Callback
84
+
85
+ SQLite / LanceDB 的 `host_callback + json` 模式可以直接通过 SDK 注册,宿主无需在业务代码中重复手写 ctypes buffer:
86
+
87
+ ```python
88
+ from luaskills import LuaSkillsClient, LuaSkillsJsonFfi
89
+
90
+ ffi = LuaSkillsJsonFfi("D:/path/to/luaskills.dll")
91
+
92
+
93
+ def sqlite_provider(request):
94
+ return {"ok": True, "request": request}
95
+
96
+
97
+ ffi.set_sqlite_provider_json_callback(sqlite_provider)
98
+
99
+ try:
100
+ client = LuaSkillsClient(
101
+ library_path="D:/path/to/luaskills.dll",
102
+ runtime_root="D:/runtime/luaskills",
103
+ host_options={
104
+ "sqlite_provider_mode": "host_callback",
105
+ "sqlite_callback_mode": "json",
106
+ },
107
+ )
108
+ client.close()
109
+ finally:
110
+ ffi.clear_sqlite_provider_json_callback()
111
+ ```
112
+
113
+ callback 必须在 `engine_new` 前注册;engine 创建后再切换 callback 不会 retroactive 影响已存在 engine。
114
+
115
+ pip 安装后的 wheel 内置可运行示例:
116
+
117
+ ```bash
118
+ python -m luaskills.examples.basic
119
+ python -m luaskills.examples.provider_callback
120
+ ```
121
+
122
+ 源码仓库中同样保留 `examples/basic.py` 与 `examples/provider_callback.py`,便于直接阅读。
123
+
124
+ ## 权限与边界
125
+
126
+ - 查询类接口默认使用 `DelegatedTool`,因此不会返回 `ROOT` skills。
127
+ - `System` 只表示可管理 ROOT 层,不表示可绕过 ROOT 同名占用规则。
128
+ - `call_skill` 与 `run_lua` 是运行时执行面,不作为 ROOT 可见性过滤。
129
+ - skill-config 按 `skill_id + key` 读写,只有 Lua skill 实际读取配置时才影响行为。
130
+ - 如果宿主不希望用户执行任意 Lua,不应直接暴露 `run_lua`。
131
+
132
+ ## 验证
133
+
134
+ 源码环境可运行:
135
+
136
+ ```bash
137
+ python -m compileall sdk/python/src
138
+ PYTHONPATH=sdk/python/src python -m luaskills.cli version --lib target/debug/luaskills.dll
139
+ ```
@@ -0,0 +1,33 @@
1
+ """
2
+ Basic Python SDK version query example.
3
+ Python SDK 基础版本查询示例。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ from pathlib import Path
10
+
11
+ from luaskills import LuaSkillsClient
12
+
13
+
14
+ def resolve_library_path() -> Path:
15
+ """
16
+ Resolve the demo LuaSkills dynamic library path.
17
+ 解析演示用 LuaSkills 动态库路径。
18
+ """
19
+
20
+ return Path(os.environ.get("LUASKILLS_LIB") or Path(__file__).resolve().parents[3] / "target" / "debug" / "luaskills.dll")
21
+
22
+
23
+ def main() -> None:
24
+ """
25
+ Print the LuaSkills JSON FFI version through the Python SDK.
26
+ 通过 Python SDK 输出 LuaSkills JSON FFI 版本。
27
+ """
28
+
29
+ print(LuaSkillsClient.version(library_path=resolve_library_path()))
30
+
31
+
32
+ if __name__ == "__main__":
33
+ main()
@@ -0,0 +1,59 @@
1
+ """
2
+ Python SDK JSON provider callback registration example.
3
+ Python SDK JSON provider callback 注册示例。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import os
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ from luaskills import LuaSkillsClient, LuaSkillsJsonFfi
13
+
14
+
15
+ def resolve_library_path() -> Path:
16
+ """
17
+ Resolve the demo LuaSkills dynamic library path.
18
+ 解析演示用 LuaSkills 动态库路径。
19
+ """
20
+
21
+ return Path(os.environ.get("LUASKILLS_LIB") or Path(__file__).resolve().parents[3] / "target" / "debug" / "luaskills.dll")
22
+
23
+
24
+ def sqlite_provider(request: Any) -> dict[str, Any]:
25
+ """
26
+ Return one minimal host-side SQLite provider response for demo requests.
27
+ 为演示请求返回一个最小宿主侧 SQLite provider 响应。
28
+ """
29
+
30
+ return {"ok": True, "request": request}
31
+
32
+
33
+ def main() -> None:
34
+ """
35
+ Register one SQLite JSON provider callback before engine creation.
36
+ 在创建引擎前注册单个 SQLite JSON provider callback。
37
+ """
38
+
39
+ library_path = resolve_library_path()
40
+ runtime_root = Path(os.environ.get("LUASKILLS_RUNTIME_ROOT") or Path(__file__).resolve().parent / "luaskills-runtime")
41
+ ffi = LuaSkillsJsonFfi(library_path)
42
+ ffi.set_sqlite_provider_json_callback(sqlite_provider)
43
+ try:
44
+ client = LuaSkillsClient(
45
+ library_path=library_path,
46
+ runtime_root=runtime_root,
47
+ host_options={
48
+ "sqlite_provider_mode": "host_callback",
49
+ "sqlite_callback_mode": "json",
50
+ },
51
+ )
52
+ client.close()
53
+ print("SQLite JSON provider callback registered before engine creation.")
54
+ finally:
55
+ ffi.clear_sqlite_provider_json_callback()
56
+
57
+
58
+ if __name__ == "__main__":
59
+ main()
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "luaskills-sdk"
7
+ version = "0.2.3"
8
+ description = "Python SDK for integrating the LuaSkills runtime through the public JSON FFI surface."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "LuaSkills" }
14
+ ]
15
+ keywords = ["lua", "skills", "ffi", "runtime", "sdk"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ ]
25
+
26
+ [project.scripts]
27
+ luaskills = "luaskills.cli:main"
28
+
29
+ [project.urls]
30
+ Repository = "https://github.com/LuaSkills/luaskills"
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.setuptools.package-data]
36
+ luaskills = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,58 @@
1
+ """
2
+ Python SDK for integrating LuaSkills through the public JSON FFI surface.
3
+ 通过公共 JSON FFI 表面集成 LuaSkills 的 Python SDK。
4
+ """
5
+
6
+ from .client import (
7
+ LuaSkillsClient,
8
+ SkillConfigClient,
9
+ SkillManagementClient,
10
+ SystemSkillManagementClient,
11
+ create_engine_options,
12
+ default_host_options,
13
+ default_pool_config,
14
+ default_space_controller_options,
15
+ )
16
+ from .ffi import JsonProviderCallback, LuaSkillsError, LuaSkillsJsonFfi, resolve_library_path
17
+ from .roots import RuntimeRoots
18
+ from .runtime_assets import (
19
+ RuntimeDatabasePreset,
20
+ build_runtime_install_manifest,
21
+ host_options_from_runtime_manifest,
22
+ install_runtime_assets,
23
+ load_runtime_install_manifest,
24
+ resolve_luaskills_library_path_from_runtime,
25
+ resolve_runtime_platform_target,
26
+ runtime_manifest_path,
27
+ write_runtime_install_manifest,
28
+ )
29
+ from .types import Authority, LuaInvocationContext, RuntimeSkillRoot, SkillInstallSourceType
30
+
31
+ __all__ = [
32
+ "Authority",
33
+ "JsonProviderCallback",
34
+ "LuaInvocationContext",
35
+ "LuaSkillsClient",
36
+ "LuaSkillsError",
37
+ "LuaSkillsJsonFfi",
38
+ "RuntimeRoots",
39
+ "RuntimeSkillRoot",
40
+ "RuntimeDatabasePreset",
41
+ "SkillConfigClient",
42
+ "SkillInstallSourceType",
43
+ "SkillManagementClient",
44
+ "SystemSkillManagementClient",
45
+ "create_engine_options",
46
+ "default_host_options",
47
+ "default_pool_config",
48
+ "default_space_controller_options",
49
+ "build_runtime_install_manifest",
50
+ "host_options_from_runtime_manifest",
51
+ "install_runtime_assets",
52
+ "load_runtime_install_manifest",
53
+ "resolve_luaskills_library_path_from_runtime",
54
+ "resolve_runtime_platform_target",
55
+ "resolve_library_path",
56
+ "runtime_manifest_path",
57
+ "write_runtime_install_manifest",
58
+ ]