Examples
AuditEffectPlugin Scenario
Use an effect scenario to show how a plugin can do side effects without rewriting the main value
AuditEffectPlugin Scenario
Scenario
You want to record an event:
- a message arrived
- an action was triggered
but you do not want to:
- transform the value
- block the flow
That is a clean effect use case.
Example
import { Plugin, type PluginHooks } from "@downcity/city/plugin";
class AuditEffectPlugin extends Plugin {
readonly name = "audit_effect";
readonly title = "Audit Effect";
readonly description = "Writes one audit line for every observed event.";
readonly hooks: PluginHooks = {
effect: {
"audit.observe": [
async ({ value, plugin }) => {
console.log(`[${plugin}] observed`, value);
},
],
},
};
}
// City has registered audit_effect and bound it to entry's Agent/Workspace.
await city.plugins.scope({ agent_id: agent.id, workspace_id: workspace.id }).effect("audit.observe", {
event: "incoming_message",
session_id: "sess_001",
});Why this is not a pipeline
Because you do not care about returning a new value. The side effect is the whole point.