notify

package
v0.1.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notify is the delivery layer for agent notifications. The daemon is a dumb, provider- agnostic EMITTER: it POSTs an agent.Notification to a webhook URL the client provisioned via PUT /notify/config. Where that webhook points — a serverless function, a Slack/ntfy relay, a push gateway (APNs/FCM), your own backend — is entirely up to you; the daemon holds no device tokens or push credentials. With no webhook configured, notifications are a silent no-op.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeliverOne

func DeliverOne(ctx context.Context, hc *http.Client, ch agent.NotifyChannel, n agent.Notification) error

DeliverOne POSTs a single notification to one channel, framed for the channel's type. It is exported so the API /notify/channels/{id}/test handler and the Go SDK can reuse the exact delivery path a live notification would take. A non-2xx response is an error (a failed send must not look successful).

func Register

func Register(f Factory)

Register adds a notifier factory. The webhook registers from this package; sub-package channels (notify/file, notify/exec) register when blank-imported by main.

Types

type BotIdentity

type BotIdentity struct {
	ID, Name, Icon, WorkspaceID string
}

BotIdentity is the saved sender, independent of the engine used by a turn.

type Factory

type Factory func(Store) (Notifier, bool)

Factory builds a Notifier from daemon state, reporting whether the channel is ENABLED. ok=false means "not configured — skip" (e.g. no NOTIFY_FILE set), so All can omit it rather than fan out to a no-op.

type Fanout

type Fanout []Notifier

Fanout delivers one notification to N channels behind a single Notifier, so the send path never grows a branch per channel. It calls EVERY channel — one channel's failure never blocks the others — and joins their errors (nil when all succeed). An empty fan-out is a silent no-op.

func (Fanout) Notify

func (f Fanout) Notify(ctx context.Context, n agent.Notification) error

type IdentityResolver

type IdentityResolver interface {
	NotificationIdentity(chatID string) (BotIdentity, error)
}

IdentityResolver is optional for legacy notification sources.

type Noop

type Noop struct{}

Noop drops notifications (used in tests / when delivery is intentionally off).

func (Noop) Notify

type Notifier

type Notifier interface {
	Notify(ctx context.Context, n agent.Notification) error
}

Notifier delivers a Notification. Implementations: WebhookNotifier (the built-in HTTP emitter), Stream (local SSE broadcaster), and Noop (disabled).

func All

func All(store Store) []Notifier

All instantiates every registered channel that is enabled for the given store, in registration order (deterministic: webhook first, then blank-import order). Disabled channels (ok=false) and nil notifiers are omitted, so the result is safe to hand straight to Fanout.

type Preferences

type Preferences interface {
	NotificationsMuted(chatID string) (bool, error)
}

Preferences is consulted immediately before delivery, across all notification transports and conditions. Implemented by the authoritative workspace registry.

type Router

type Router struct {
	Store RouterStore
	HTTP  *http.Client
}

Router delivers a notification to every channel selected by a matching, enabled rule.

func (*Router) Notify

func (r *Router) Notify(ctx context.Context, n agent.Notification) error

type RouterStore

type RouterStore interface {
	NotifyChannels() []agent.NotifyChannel
	NotifyRules() []agent.NotifyRule
}

RouterStore is the slice of daemon state the Router reads: the configured channels and rules. It is deliberately SEPARATE from notify.Store (which only exposes NotifyConfig) so the existing Store interface — and its test fakes — never have to grow these methods. The session store satisfies both structurally; the factory type-asserts to discover whether routing is available.

type Store

type Store interface {
	NotifyConfig() (url, channel, token string)
}

Store is the subset of daemon state a notifier factory may read to configure its channel. The session store satisfies it structurally (no import cycle). The webhook channel reads its runtime-configurable target from it; env-configured channels (notify/file, notify/exec) ignore it and read their own os.Getenv config — deliberately keeping local-trust hooks OUT of API-mutable state.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is an in-process notification broadcaster that also implements Notifier. The daemon fans every emitted notification to it alongside the webhook push, so local clients (the web console, dev tooling) can watch notifications live over SSE without depending on any external delivery. It keeps a small replay ring so a just-connected client still sees the last few. Slow subscribers are dropped, never block a turn.

func NewStream

func NewStream() *Stream

func (*Stream) Notify

func (s *Stream) Notify(_ context.Context, n agent.Notification) error

Notify implements Notifier: record into the replay ring + broadcast (non-blocking).

func (*Stream) Subscribe

func (s *Stream) Subscribe() (<-chan agent.Notification, []agent.Notification, func())

Subscribe returns a live channel, the current replay buffer, and an unsubscribe func.

type WebhookNotifier

type WebhookNotifier struct {
	// Config returns (url, channel, token): the webhook endpoint, an optional routing tag sent as
	// the X-Mindwire-Channel header, and an optional bearer token sent as Authorization.
	Config func() (url, channel, token string)
	Format func() agent.NotifyChannelType
	HTTP   *http.Client
}

WebhookNotifier delivers a notification by POSTing it to a user-configured webhook URL. It is provider-agnostic: the daemon just fires the agent.Notification as JSON at whatever endpoint the client provisioned via PUT /notify/config — a serverless function, a Slack/ntfy relay, a push gateway (APNs/FCM), your own backend, anything that speaks HTTP. The daemon holds no device tokens or push credentials. The optional push format wraps routing metadata in string-valued data for a push relay; final FCM/APNs shaping/fan-out is the receiver's job.

It reads its target LIVE from a provider on every send, so the client can set or rotate the webhook at runtime. With no URL configured it is a silent no-op — notifications are optional and off by default.

func NewWebhook

func NewWebhook(config func() (url, channel, token string)) *WebhookNotifier

NewWebhook builds a notifier that reads its target from config on each send.

func (*WebhookNotifier) Notify

Directories

Path Synopsis
Package exec is a notification channel that runs a local command (named by NOTIFY_EXEC) with the notification JSON on stdin — a true local hook (desktop toast, log shipper, pager, …).
Package exec is a notification channel that runs a local command (named by NOTIFY_EXEC) with the notification JSON on stdin — a true local hook (desktop toast, log shipper, pager, …).
Package file is a notification channel that appends each notification as one JSON line (JSONL) to a local file named by NOTIFY_FILE.
Package file is a notification channel that appends each notification as one JSON line (JSONL) to a local file named by NOTIFY_FILE.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL