iii-effect-system
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEffect Systems & Typed Functional Infrastructure
效应系统与类型化函数式基础设施
Comparable to: Effect-TS
类似技术:Effect-TS
Key Concepts
核心概念
Use the concepts below when they fit the task. Not every effect pipeline needs all of them.
- Each effect is a registered function with a single responsibility (parse, enrich, persist, notify)
- Effects compose by calling one function from another via
trigger - The entire pipeline is traceable end-to-end through OpenTelemetry
- Errors propagate naturally — a failing effect stops the chain
- An HTTP trigger provides the entry point; effects chain from there
当任务适配时使用以下概念,并非所有效应管道都需要全部概念。
- 每个效应都是一个具有单一职责的已注册函数(解析、增强、持久化、通知)
- 效应通过调用另一个函数来实现组合
trigger - 整个管道可通过OpenTelemetry实现端到端追踪
- 错误会自然传播——失败的效应会终止整个链条
- HTTP触发器作为入口点,效应从这里开始链式执行
Architecture
架构
text
HTTP request
→ fx::parse-user-input (validate + normalize)
→ fx::enrich (add metadata, lookup external data)
→ fx::persist (write to state)
→ fx::notify (fire-and-forget side effect)
← composed result returned to callertext
HTTP request
→ fx::parse-user-input (validate + normalize)
→ fx::enrich (add metadata, lookup external data)
→ fx::persist (write to state)
→ fx::notify (fire-and-forget side effect)
← composed result returned to calleriii Primitives Used
使用的iii原语
| Primitive | Purpose |
|---|---|
| Initialize the worker and connect to iii |
| Define each effect |
| Compose effects synchronously |
| Fire-and-forget side effects |
| Persist data between effects |
| Entry point |
| 原语 | 用途 |
|---|---|
| 初始化worker并连接到iii引擎 |
| 定义每个效应函数 |
| 同步组合效应函数 |
| 触发即发即弃的副作用 |
| 在效应之间持久化数据 |
| 定义管道入口点 |
Reference Implementation
参考实现
See ../references/effect-system.js for the full working example — a user signup pipeline
where input is parsed, enriched with external data, persisted to state, and a welcome notification is fired.
完整可运行示例请参见../references/effect-system.js —— 这是一个用户注册管道,其中输入会被解析、补充外部数据、持久化到状态中,并触发欢迎通知。
Common Patterns
常见模式
Code using this pattern commonly includes, when relevant:
- — worker initialization
registerWorker(url, { workerName }) - — synchronous composition (effect A calls effect B)
trigger({ function_id, payload }) - Each effect as its own with
registerFunctionprefix IDsfx:: - Error throwing for validation failures (errors propagate up the chain)
- — fire-and-forget for non-critical side effects
trigger({ ..., action: TriggerAction.Void() }) - — structured logging per effect
const logger = new Logger()
使用该模式的代码通常包含以下内容(相关时):
- —— worker初始化
registerWorker(url, { workerName }) - —— 同步组合(效应A调用效应B)
trigger({ function_id, payload }) - 每个效应都是独立的,函数ID以
registerFunction为前缀fx:: - 验证失败时抛出错误(错误会沿链条向上传播)
- —— 对非关键副作用使用即发即弃模式
trigger({ ..., action: TriggerAction.Void() }) - —— 为每个效应添加结构化日志
const logger = new Logger()
Adapting This Pattern
模式适配
Use the adaptations below when they apply to the task.
- Replace simulated logic with real work (API calls, database queries, ML inference)
- Add new effects by registering functions and calling them via
trigger - For unreliable steps, use instead of synchronous
TriggerAction.Enqueue({ queue })trigger - Keep effects pure where possible — accept input, return output, no hidden side effects
- Function IDs should be domain-prefixed (e.g. ,
fx::validate-email)fx::geocode-address
当任务适配时,可进行以下调整:
- 用实际业务逻辑替换模拟逻辑(API调用、数据库查询、机器学习推理)
- 通过注册新函数并使用调用的方式添加新效应
trigger - 对于不可靠的步骤,使用替代同步
TriggerAction.Enqueue({ queue })trigger - 尽可能保持效应的纯函数特性——接收输入、返回输出,无隐藏副作用
- 函数ID应添加领域前缀(例如、
fx::validate-email)fx::geocode-address
Pattern Boundaries
模式边界
- If a request is about durable multi-step workflows with retries and DLQ handling, prefer .
iii-workflow-orchestration - If the task involves multiple independent agents handing off work, prefer .
iii-agentic-backend - Stay with when the primary concern is composable, traceable function pipelines with synchronous chaining.
iii-effect-system
- 如果需求是具备重试和死信队列(DLQ)处理的持久化多步骤工作流,优先选择。
iii-workflow-orchestration - 如果任务涉及多个独立代理交接工作,优先选择。
iii-agentic-backend - 当核心需求是构建可组合、可追踪且同步链式执行的函数管道时,使用。
iii-effect-system
When to Use
使用场景
- Use this skill when the task is primarily about in the iii engine.
iii-effect-system - Triggers when the request directly asks for this pattern or an equivalent implementation.
- 当任务主要围绕iii引擎中的展开时,使用该技能。
iii-effect-system - 当请求直接要求实现该模式或等效方案时触发。
Boundaries
边界限制
- Never use this skill as a generic fallback for unrelated tasks.
- You must not apply this skill when a more specific iii skill is a better fit.
- Always verify environment and safety constraints before applying examples from this skill.
- 切勿将该技能作为无关任务的通用 fallback 方案。
- 当有更合适的特定iii技能时,不得使用该技能。
- 在应用该技能的示例前,务必验证环境和安全约束。