modify: rust worker

This commit is contained in:
2026-08-22 03:27:32 +08:00
parent 541a9b5e33
commit 3cc8a63c1d
5 changed files with 64 additions and 0 deletions
+25
View File
@@ -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"
+11
View File
@@ -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 }
+5
View File
@@ -0,0 +1,5 @@
# rsdemo.error —— 恒抛业务异常,演示非流式错误回复格式
# ({"result":0.0,"operation":"error","error":...,"worker":...})
[GET]
summary = "Rust 参考插件:模拟业务异常"
auth_required = false
+10
View File
@@ -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 }
+13
View File
@@ -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"
]