Skip to content
Skillpedia
General coding19k · #10496

iii-observe

What it does

Shows how to make one function react to events from another function, without changing the original. It is for developers who want to add alerts, logging or follow-up work to an existing iii function.

When to use it

  • ✓When you want to run follow-up work after another function succeeds or fails.
  • ✓When you want to add alerting or logging to an existing function without editing it.
  • ✓When you are moving older trigger code to the newer observer approach.

Skill link

https://github.com/iii-hq/iii/blob/main/skills/iii-observe/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/iii-hq/iii/blob/main/skills/iii-observe/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Alert me whenever the orders::validate function fails, without changing its code.”

5 new skills a week. 1 minute to read.

How it works

The skill connects a source function to a target with an observer, adding filters if needed. Each event that passes the filters invokes the target. The observer waits until the target is registered, and the older trigger approach still works for now.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Observe

Since iii 0.25 every function is observable. iii.observe(source, target, options?) connects a source function to a target function: each event of the source that passes the observer's filters invokes the target. It replaces registerTrigger, and an observe descriptor on registerFunction replaces registerTriggerType. Both old APIs still work in 0.25 (see Migrating from triggers).

Part Fields Notes
source (left side) function_id, namespace?, args?, filters?, on?, capture?, deliver? args only for owner-delivered functions. on (auto only): success (default), error, complete. capture (auto and obs.emit): default ['input', 'output', 'caller'], [] allowed. deliver: envelope (default), input, output
target (right side) a registered function id (or { function_id, namespace }) No inline handler. The observer stays pending until the target is registered
options id?, max_fires?, expires_in_ms?, max_in_flight?, metadata? id defaults to a UUID kept across replays. metadata is the sidecar of every activation

The source namespace resolves like trigger(): the worker's namespace, except engine::* and configuration::*, which resolve in default.

Observe a function

Register the target first, then observe. This alerts on failed charges of 500 or more:

import { registerWorker, type Observed } from "iii-sdk";

const iii = registerWorker(process.env.III_URL ?? "ws://localhost:49134");

iii.registerFunction("alerts::payment-failed", async (event: Observed<{ amount: number }>) => {
  console.log(event.function_id, event.error?.code, event.input?.amount, event.caller?.worker_name);
  return null; // ignored for auto delivery
});

const failures = iii.observe(
  {
    function_id: "payments::charge",
    on: "error",
    filters: { "input.amount": { $gte: 500 } },
    capture: ["input", "error", "caller"],
  },
  "alerts::payment-failed",
  { max_in_flight: 4 },
);
await failures.ready(); // rejects with ObserveRejection (error.code) on error or disposed
// later: await failures.dispose()
iii.register_function("alerts::payment-failed", lambda event: print(event["error"]["code"]))

failures = iii.observe(
    {"function_id": "payments::charge", "on": "error",
     "filters": {"input.amount": {"$gte": 500}}, "capture": ["input", "error", "caller"]},
    "alerts::payment-failed",
    {"max_in_flight": 4},
)
failures.ready()  # blocks; in async code: await failures.ready_async()
use iii_sdk::{Capture, Error, ObserverOptions, Observed, On, RegisterFunction, Source};
use serde_json::{json, Value};

iii.register_function(
    "alerts::payment-failed",
    RegisterFunction::new(|event: Observed<Value>| {
        println!("{} failed: {:?}", event.function_id, event.error);
        Ok::<_, Error>(())
    }),
);
let failures = iii.observe_with(
    Source::function("payments::charge")
        .on(On::Error)
        .filters(json!({ "input.amount": { "$gte": 500 } }))
        .capture([Capture::Input, Capture::Error, Capture::Caller]),
    "alerts::payment-failed",
    ObserverOptions::default().max_in_flight(4),
);
failures.ready().await?;
client.RegisterFunction("alerts::payment-failed", func(ctx context.Context, data json.RawMessage) (any, error) {
	var ev iii.Observed
	if err := json.Unmarshal(data, &ev); err != nil {
		return nil, err
	}
	log.Printf("%s failed: %s", ev.FunctionID, ev.Error.Code)
	return nil, nil
})
failures, err := client.Observe(iii.Source{
	FunctionID: "payments::charge",
	On:         iii.OnError,
	Filters:    iii.Filters{"input.amount": iii.Op{"$gte": 500}},
	Capture:    []iii.Capture{iii.CaptureInput, iii.CaptureError, iii.CaptureCaller},
}, "alerts::payment-failed", iii.ObserverOptions{MaxInFlight: 4})
if err == nil {
	err = failures.Ready(ctx) // *iii.ObserveRejectionError carries the code
}

The browser SDK (iii-browser-sdk) has the same observe API as Node.

What the target receives

  • Envelope (default deliver): { observer_id, activation_id, function_id, namespace, invocation_id, status, input?, output?, error?, caller?, metadata?, started_at_ms, duration_ms }. Only captured fields are present. deliver: 'input' or 'output' sends that value alone.
  • The observer's options.metadata arrives as the handler's metadata argument (Node and browser second argument, Python `met
FAQ

Does the source function need changes?

No. An observer connects to it from outside, without editing its code.

Can I filter which calls run the observer?

Yes. Filters decide which events invoke the target.

Is the older trigger approach still supported?

Yes. It still works in this version, although the observer approach is the newer one.

Details

Original description by the author

Use when observing iii functions with iii.observe, writing filters, reacting to engine events, writing observable functions with owner delivery (onObserverAdded, obs.emit, obs.call), tuning local dispatch, or migrating from the deprecated registerTrigger / registerTriggerType across TypeScript, browser, Python, Rust, and Go.

repo: iii-hq/iii

Popularity

GitHub stars
19k
Ranking position
#10496
License
—
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills