relay-client

Implements lifecycle-aware Nostr relay subscriptions and filter assembly for Amethyst composables.

1.6k|222|Updated Jan 11, 2023
One-click install
npx skills add https://github.com/vitorpamplona/amethyst --skill relay-client
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: relay-client
Source: https://github.com/vitorpamplona/amethyst/tree/main/.claude/skills/relay-client
Command: npx skills add https://github.com/vitorpamplona/amethyst --skill relay-client

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Building Nostr clients in Compose risks leaking relay subscriptions, duplicating filters across screens, and overwhelming relays with bulk metadata requests. This Skill documents the Amethyst relay-client layer so composables subscribe only to visible data, deduplicate filters, and handle EOSE transitions correctly.

Core Features & Use Cases

  • Compose-Scoped Subscriptions: Use Subscribable<T> and ComposeSubscriptionManager with reference counting so multiple screens share one subscription and the last leaver closes it.
  • Pure Filter Assemblers: Build relay Filter objects via testable classes like MetadataFilterAssembler and ReactionsFilterAssembler instead of inline filter logic in composables.
  • Rate-Limited Preloading: Batch bulk metadata fetches through MetadataPreloader and MetadataRateLimiter to avoid relay rate limits.
  • Use Case: When adding a profile screen that needs kind-0 metadata for visible users, wire observeUserInfo(user) in the composable so metadata loads only while the user is on screen and unsubscribes after they leave.

Quick Start

Ask the AI to wire a new composable screen to subscribe to relay metadata for its visible pubkeys using the Amethyst relay-client Subscribable and assembler patterns.

Frequently Asked Questions about relay-client

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I subscribe to Nostr relay data from a Jetpack Compose screen?

Create a Subscribable via a filter assembler, call subscribe() in a LaunchedEffect, and unsubscribe() in a DisposableEffect onDispose block. This ties the relay subscription to the composable lifecycle so it closes when the user navigates away.

How do I build a Nostr relay filter for metadata or reactions?

Write a pure assembler class like MetadataFilterAssembler that takes pubkeys or note ids and exposes a toFilter() method returning a quartz Filter. Keep assemblers side-effect-free so they are trivially unit-testable against stable filter JSON serialization.

How do I avoid duplicate relay subscriptions across multiple screens?

Use MutableComposeSubscriptionManager, which reference-counts identical subscriptions so concurrent screens share one relay subscription. Only the last screen to leave actually closes the underlying subscription.

Can I fetch metadata for hundreds of pubkeys without rate limits?

Route bulk fetches through MetadataPreloader, which uses the MetadataRateLimiter token bucket to batch requests into relay-friendly chunks. Do not fire individual subscriptions per pubkey, and cancel preload requests when the screen unmounts.

When should I use a Subscribable versus a one-shot relay fetch?

Use Subscribable for compose-scoped, user-visible data that needs lifecycle management. For headless or one-shot operations like CLI tools and tests, use the INostrClient extension functions such as fetchAll or fetchFirst in the quartz accessories package.