Skip to content

Component: Smrt.Contracts.Triggers

Canonical source: SmrtApps/src/Smrt.Contracts.Triggers/README.md (mirrored below)


Smrt.Contracts.Triggers

Overview & Responsibilities

  • Defines the contracts and transport abstractions used to dispatch SmrtHub trigger events (hotkeys, automation hooks).
  • Provides a reference HTTP dispatcher implementation for local host scenarios across Python and C# runtimes.
  • Keeps payload shapes lightweight to remain portable between desktop and service environments.

Dependencies & Integrations

  • Targets .NET 8 and ships without additional NuGet dependencies to minimize footprint.
  • Consumed by trigger producers (e.g., HubWindow) and trigger workers (e.g., PythonApp) to ensure consistent message formats.

Configuration & Log Paths

  • The library itself does not read configuration or emit logs; hosts combine it with Smrt.Config/Smrt.Logging to apply canonical settings.
  • HTTP endpoints used by HttpTriggerDispatcher should be sourced from the consuming app’s configuration overlay in %APPDATA%/SmrtHub/Config/<component>/.

Runtime Flows

  • UI or background components call ITriggerDispatcher.Dispatch with a logical hotkey; implementations route the message to the appropriate runtime.
  • The default HTTP dispatcher posts JSON payloads (e.g., { "hotkey": "HOTKEY_SMRTSAVE" }) to the configured endpoint using a shared HttpClient with a 5-second timeout and fire-and-forget semantics.
  • Consumers can supply an onDispatchFailure callback to bridge exceptions into SmrtHub.Logging or other telemetry stacks without creating a hard dependency from this contracts assembly.

Public surface

The primary public surface is the dispatch contract and the default HTTP implementation described below.

Key APIs

  • ITriggerDispatcher.Dispatch(string hotkey) – fire-and-forget dispatch contract; expects logical hotkeys and throws ArgumentException on empty values.
  • HttpTriggerDispatcher – loopback HTTP implementation with URI validation, shared connection management, and optional failure callback for logging hookups.

Testing & Validation

  • Consumers should cover trigger dispatch paths with integration tests to verify the correct endpoint receives the payload.
  • When wiring HttpTriggerDispatcher, unit-test the onDispatchFailure callback to ensure logging or telemetry sinks capture dispatch failures as expected.
  • When modifying payload schema, update both the dispatcher and worker expectations in lockstep to avoid runtime mismatches.

Support Bundle & Diagnostics

  • Trigger dispatch failures are surfaced via hosting application logs; no support-bundle assets originate from this library directly.

Subdirectories

  • None beyond build outputs (bin/, obj/).
  • TriggerManager component (hotkey producer and routing): SmrtApps/CSApps/TriggerManager/README.md
  • Shell surfaces capability (tray/taskbar routes into triggers): README.Files/Capabilities/Shell-Surfaces/README.md