-
Notifications
You must be signed in to change notification settings - Fork 1
Typert zh
上游类型安全远程调用系统在 Edge 中的适配。
上游参考:Typert
Typert 是一个类型安全的 RPC 框架,从 TypeScript 服务方法签名自动生成 endpoint descriptor。三层架构:
-
TypertRegistry(
ctx.typert)— 管理生成的 schema、包反射、lookup 和 context provider。 -
TypertGatewayService(
ctx.typertGateway)— 宿主端分发器。解析严格生成定义或 SRC 标记,校验参数,调用业务方法。 -
Client Remote(
ctx.remote)— 浏览器端消费者。挂载生成的 descriptor 为类型化方法,通过connection.rpc.call发送 RPC。
像 GoalService 这样的 Service 继承 TypertRemoteService 并用 @Remote 装饰器标记方法。Gateway 通过 SRC 反射自动发现——不需要手动路由。
TypertRegistry 和 TypertGatewayService 原封安装。SRC 反射、lookup 解析、参数校验和编解码完全是上游代码。
上游用 Connection.rpc.intercept('/api', ...) 在 webserver 的复合 handler 上注册 gateway。Edge 没有 Connection 服务。handleTypertRpc()(约 20 行)通过正则拦截 /api/{namespace}/{method} URL,从请求体提取 args,调用 gateway.invoke(),包装为 ServerResponse 返回。
- SRC 反射和严格 descriptor 解析
- Lookup 和 context provider 注册
- 参数校验和编解码
- 错误分类(
TypertGatewayError码) - 客户端
ctx.remote行为
请求路径:HTTP POST → 正则匹配 → JSON 解析 → gateway.invoke() → SRC 反射 → 方法调用 → 响应。SRC 每个 endpoint 扫描一次并缓存。后续调用跳过发现。业务方法(如 GoalService.edit())是同步的。DO 内典型往返:个位数毫秒。
任何有 @Remote 装饰方法的 cordis Service 自动可路由——不需要 Edge 代码。当前覆盖 goals(6 个方法)。未来的 Service 免费获得路由。
| 组件 | 分类 | Edge 代码 |
|---|---|---|
| TypertRegistry | 复用 | 一行 ctx.plugin()
|
| TypertGatewayService | 复用 | 一行 ctx.plugin()
|
| HTTP 路由 | 桥接 |
handleTypertRpc()(约 20 行) |
| Client Remote | 复用 | 上游客户端插件 |
关键观察:Edge 的 Typert 适配是一个约 20 行的传输桥,将 HTTP POST 翻译为
gateway.invoke()。其他一切——发现、校验、分发、错误处理——都是上游代码。新增@RemoteService 需要零 Edge 改动。
- Home
- Architecture
- Core & Scope
- Session & Persistence
- Model & Context
-
Execution & Tools
- Tools
- Bash
- Subprocess 🚫
- PTY Session 🚫
- Background Jobs 🚫
- Filesystem
- LSP Navigation 🚫
- Code Runtime 🚫
-
Web Access
⚠️ -
Skills
⚠️ - Workflow 🚫
- Subagent 🚫
-
Policy & Interaction
- Goal
- Approval 🚫
- Permission Presets 🚫
-
Sandbox
⚠️ - Plan Mode 🚫
- User Interaction 🚫
- Commands 🚫
- Schedule 🚫
- Message Feedback 🚫
- Platform & Access
- Development
- 首页
- 架构
- 核心与作用域
- 会话与持久化
- 模型与上下文
- 执行与工具
- 策略与交互
- 平台与接入
- 开发