Metadata-Version: 2.4
Name: ls-algorithm-plugin-sdk
Version: 0.2.5
Summary: Protocol-independent runtime SDK for dataset algorithms
Author: Ling Robotics
License: Proprietary
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: service
Requires-Dist: fastapi<1,>=0.110; extra == "service"
Requires-Dist: pydantic<3,>=2.0; extra == "service"
Requires-Dist: uvicorn[standard]<1,>=0.29; extra == "service"
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"

# Algorithm Plugin SDK

算法仓库只实现一个 `Algorithm` 类并声明 entry point。SDK
统一提供单次运行、WebUI、HTTP service、release manifest、compute 注册、心跳以及裸机进程管理。
算法仓库不需要 Dockerfile、Web 框架代码或 service 启停脚本。

## 算法侧最小接口

```python
from algorithm_plugin_sdk import Algorithm

class MyAlgorithm(Algorithm):
    @classmethod
    def metadata(cls): ...
    def execute(self, request, context): ...
```

算法包声明 `algorithm_plugin_sdk.algorithms` entry point，并在仓库根目录发布只读的
`release-manifest.json`。同一个 `execute()` 会被所有运行方式复用。

## 单次运行

```bash
algorithm-plugin run camera-space-mano \
  --input '{"dataset":"/data/input"}' \
  --output-dir /data/output
```

## 一次生成、一次启动、一次停止

在算法仓库根目录执行：

```bash
algorithm-plugin config \
  --compute-url http://compute:5180 \
  --api-key "$LDP_INTERNAL_API_KEY" \
  --public-url http://10.0.0.4:9000 \
  --input-root /data/jobs/input \
  --workspace-root /data/jobs/workspace \
  --cluster production \
  --namespace camera-space-mano \
  --node-name 10.0.0.4 \
  --gpu-ids 0

algorithm-plugin start
algorithm-plugin stop
```

`gpu_ids` 属于部署配置，不由 `/v1/executions` 请求提供。SDK 启动服务后会将配置的
GPU IDs 自动注入每个 `AlgorithmRequest`。

`config` 自动发现当前仓库和唯一 Algorithm entry point，并从 `release-manifest.json`
补齐 algorithm type、version、implementation digest、build revision、schema、启动入口、
PID 和日志路径。生成的 `algorithm-plugin.json` 权限为 `0600`。开发环境可使用
`algorithm-plugin config --local` 跳过 compute 注册。

`start` 默认在后台启动 `0.0.0.0:9000`，同时提供 `/ui/` 和 `/v1/*`，自动注册并每
5 秒心跳。日志写到 `.algorithm-plugin/service.log`。`stop` 只终止 PID、启动时间和命令行
均匹配当前配置的 SDK 进程，避免误杀复用 PID 的其他进程。

需要前台运行（例如 systemd）时仍可使用：

```bash
algorithm-plugin serve camera-space-mano --port 9000 --webui
```

## 安装与测试

```bash
python -m pip install '.[service]'
python -m unittest discover -s tests -v
```
