본문으로 건너뛰기
Skillpedia
일반 코딩19k · #10496

iii-observe

하는 일

원본 함수를 고치지 않고, 한 함수가 다른 함수의 이벤트에 반응하게 만드는 방법을 보여 줍니다. 기존 iii 함수에 알림, 로그 기록, 후속 작업을 추가하려는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓다른 함수가 성공하거나 실패한 뒤 후속 작업을 실행하고 싶을 때.
  • ✓기존 함수를 수정하지 않고 알림이나 로그 기록을 추가하고 싶을 때.
  • ✓예전 트리거 코드를 새 옵저버 방식으로 옮기는 중일 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

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.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“orders::validate 함수가 실패할 때마다 알려 주세요. 그 함수의 코드는 바꾸지 마세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 옵저버로 원본 함수를 대상 함수에 연결하고, 필요하면 필터를 추가합니다. 필터를 통과한 이벤트마다 대상이 호출됩니다. 옵저버는 대상이 등록될 때까지 기다리며, 예전 트리거 방식도 당분간은 계속 동작합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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
자주 묻는 질문

원본 함수를 바꿔야 하나요?

아니요. 옵저버는 원본 함수의 코드를 고치지 않고 바깥에서 연결합니다.

옵저버가 실행될 호출을 걸러낼 수 있나요?

네. 필터가 어떤 이벤트로 대상을 호출할지 정합니다.

예전 트리거 방식도 여전히 지원되나요?

네. 이 버전에서도 동작하지만, 새 방식은 옵저버입니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
19k
순위
#10496
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬