Define shared event subscriptions and handler input in adapter-core

Closed
WI
3mo ago
+654-0

Cloud and authored Flows need a shared boundary between subscription selection and handler execution. Today their envelopes differ, and generated flow code repeats source checks inside runs. This adds @relayfile/adapter-core/events: catalog-backed subscription declarations and validated event snapshots that downstream hosts can use before starting a handler.

  • defineEventSubscription / parseEventSubscription describe a connection, exact adapter event types, and optional concrete path prefixes. Unknown selectors fail closed.
  • createAdapterEvent / parseAdapterEvent preserve existing logical event identity, transport identity, verified-context fields, paths and JSON payload as immutable snapshots.
  • Reuses the existing trigger catalog; adds no provider inventory, credentials, filter execution, dedupe store or Flows runtime.
  • Documents host matching/authentication/durable-delivery responsibilities and the Cloud envelope bridge. Nonmatching events should create no run. Provider payload semantics remain adapter-specific.

Validation

The required repository gate completed with exit 0:

PATH="/tmp/flows-ci-toolchain/node_modules/.bin:$PATH" npm_config_cache=/tmp/relayfile-event-npm-cache npx turbo build typecheck test > /tmp/relayfile-event-gate.log 2>&1

Captured final output excerpt:

 Tasks:    157 successful, 157 total
Cached:    0 cached, 157 total
  Time:    39.36s

New public-export tests cover all catalog events, provider/event type mismatches, schema/selector refusal, immutable snapshots, provenance, paths, identity preservation and JSON validation. A packed consumer and browser-target bundle also agree on the serialized contract. Commands and captured evidence.

Release and downstream work

After human review and merge, publish core (@relayfile/adapter-core) through the publish workflow. This feature PR does not bump versions. No provider packages or mount resync are required for this additive contract.

Then consume the published version in Flows and Cloud: wire .on(source, handler), one-off CLI supplied events, authenticated Cloud delivery, stable event identity and handler binding. Finally update the builder to generate that supported shape. This PR alone does not make those execution paths work; the staged contract is in event-subscriptions.md.

Flows PR https://github.com/AgentWorkforce/flows/pull/401 remains a separate completion-handling/schema repair. Its cancellation fixture now represents an explicit request to stop work, not a filter mismatch.


[!NOTE]
Low Risk
Additive contract and validation layer with no runtime listeners or execution changes; downstream hosts must still implement matching, auth, and dedupe correctly when they adopt it.

Overview
Introduces @relayfile/adapter-core/events, a new browser-safe subpath for versioned event subscription declarations and handler event envelopes that Cloud and Flows can share before starting a run.

Subscriptions use defineEventSubscription / parseEventSubscription with schema relayfile.event-subscription/1: provider, connectionId, exact catalog-backed eventTypes, and optional concrete pathPrefixes. Unknown providers, event names, schema versions, or extra selector fields are rejected.

Handler input uses createAdapterEvent / parseAdapterEvent with schema relayfile.adapter-event/1: preserves upstream logical id separately from optional transport deliveryId, plus workspace/connection context, canonical timestamps, adapter-mapped paths, and frozen JSON payload. Parsing validates shape and catalog names only—no auth, matching, or deduplication (documented as host responsibilities).

The package export is wired in package.json, re-exported from the core entrypoint, covered by contract.test.ts, and documented in docs/event-subscriptions.md with rollout notes for Flows/Cloud. Verification notes confirm turbo gate and packed/browser bundle parity.

Reviewed by Cursor Bugbot for commit d0fd82bd12289d0276a2b3abe5d6f79eaf657ccb. Bugbot is set up for automated code reviews on this repo. Configure here.