diff --git a/workers/rsdemo/config.toml b/workers/rsdemo/config.toml new file mode 100644 index 0000000..60e24b4 --- /dev/null +++ b/workers/rsdemo/config.toml @@ -0,0 +1,25 @@ +# ====== 插件注册信息(Rust 参考插件 rsdemo) ====== +# 与 Python SDK 共用同一套 TOML 端点定义格式(docs/plugin-wire-protocol.md §2), +# 由 chongming-worker-rs 解析并发布路由描述符。 +[workers] +type = "rsdemo" +module = "rsdemo" # Rust 插件无 Python 模块概念,字段保留用于记录 +factory = "create_workers" +cleanup = "cleanup" +count = 2 +load_mode = "external" # 独立进程运行,经 Zenoh 注册路由 + +[worker] +name = "rsdemo" +version = "0.1.0" +description = "进程插件 Rust 参考实现(多语言演进规划阶段 1)" +config_version = "1.0" +defaults = { method = "GET", timeout = 30.0, auth_required = false, cacheable = false, internal = false } + +[worker.registration] +router_prefix = "/rsdemo" +tags = ["rsdemo", "process-plugin", "rust"] + +# ====== Worker 运行时配置(由 Rust SDK 展平后传给 handler) ====== +[workers.config] +greeting_prefix = "Hello" diff --git a/workers/rsdemo/echo.toml b/workers/rsdemo/echo.toml new file mode 100644 index 0000000..758bfcf --- /dev/null +++ b/workers/rsdemo/echo.toml @@ -0,0 +1,11 @@ +# rsdemo.echo —— POST 端点,演示 user_info 信封透传 +[POST] +summary = "Rust 参考插件:回声(透传网关认证用户信息)" +params = ["msg: str"] +auth_required = true + +[POST.response_model] +echo = { type = "str", required = true } +user_info = { type = "any", required = false } +worker_id = { type = "str", required = false, default = "" } +timestamp = { type = "float", required = true } diff --git a/workers/rsdemo/error.toml b/workers/rsdemo/error.toml new file mode 100644 index 0000000..fcb566f --- /dev/null +++ b/workers/rsdemo/error.toml @@ -0,0 +1,5 @@ +# rsdemo.error —— 恒抛业务异常,演示非流式错误回复格式 +# ({"result":0.0,"operation":"error","error":...,"worker":...}) +[GET] +summary = "Rust 参考插件:模拟业务异常" +auth_required = false diff --git a/workers/rsdemo/hello.toml b/workers/rsdemo/hello.toml new file mode 100644 index 0000000..10f7c5d --- /dev/null +++ b/workers/rsdemo/hello.toml @@ -0,0 +1,10 @@ +# rsdemo.hello —— 普通 GET 端点(对位 Python demo.hello) +[GET] +summary = "Rust 参考插件:问候" +params = ["name: str"] +auth_required = false + +[GET.response_model] +greeting = { type = "str", required = true } +worker_id = { type = "str", required = false, default = "" } +timestamp = { type = "float", required = true } diff --git a/workers/rsdemo/stream.toml b/workers/rsdemo/stream.toml new file mode 100644 index 0000000..f79f45b --- /dev/null +++ b/workers/rsdemo/stream.toml @@ -0,0 +1,13 @@ +# rsdemo.stream —— 流式端点(SSE,逐块多回复) +[POST] +summary = "Rust 参考插件:模拟 AI 流式输出(SSE,逐 token)" +docstring = "流式端点:Rust handler 返回流,逐块多回复推送,网关以 text/event-stream 转发。tokens > 50 时第 26 块抛错,演示 {\"error\": ...} 收尾块。" +auth_required = false +stream = true +# 流式超时模型: timeout = 流总寿命上限(zenoh query deadline) +timeout = 300.0 +stream_idle_timeout = 10.0 +params = [ + "prompt: str", + "tokens: int" +]