Class ActivityRecorder

java.lang.Object
dyntabs.ai.activity.ActivityRecorder

@ApplicationScoped public class ActivityRecorder extends Object
The single application-facing entry point for writing to the ambient activity timeline — a thin facade over the ActivityStore that stamps each event with the current session and tab, so callers never have to figure out "where am I" themselves.

What this class is for

Two kinds of caller record activity, and both go through here:

  • the ActivityTrackedInterceptor, automatically, for every @ActivityTracked method;
  • your own beans, manually, for things an annotation can't express (a free-text note typed into a field, a multi-step wizard completing) — e.g. recorder.record(Type.NOTE, "note", null, body).

Centralising it means the rule for "which session/tab does this belong to" lives in one place and is applied consistently, whichever path recorded the event.

Familiar analogy: the front desk where everyone drops off their timesheets. Whether the entry came from an automatic badge-reader (the interceptor) or someone filling in a slip by hand (manual calls), the front desk stamps it with today's date and the right department (session + tab) before filing it. The filing cabinet itself is the ActivityStore.

How the result is used

Everything recorded here lands in the ActivityStore, from which an ActivityContext later reads a recent slice to inject into the assistant's prompt. In other words, this class is the write-end of the loop whose read-end is ActivityContext.render().

See Also:
  • Constructor Details

    • ActivityRecorder

      public ActivityRecorder()
  • Method Details

    • record

      public void record(UserActivityEvent event)
      Record a fully-built event, filling in the current session and tab if the caller left them unset.

      Called by ActivityTrackedInterceptor (which builds the event from method metadata) and by any bean holding a pre-built UserActivityEvent. The event is then handed to the ActivityStore, where it waits to be read back by an ActivityContext.

      Parameters:
      event - the event to store; must not be null. If its sessionId/tabId are null, they are stamped from the current context before storing.
    • record

      public void record(UserActivityEvent.Type type, String verb, List<EntityRef> entities, String text)
      Convenience builder-and-record for callers that don't want to assemble a UserActivityEvent.

      Stamps the current session/tab and timestamp automatically, then delegates to record(UserActivityEvent). Handy for manual notes/searches from a backing bean.

      Parameters:
      type - the event category (required)
      verb - the act in your vocabulary (may be null)
      entities - the business objects touched (may be null or empty)
      text - authored text such as a note or query (may be null)
    • currentTabId

      public String currentTabId()
      Resolve the id of the tab the caller is currently acting in.

      Used internally to stamp events; reads from TabScopedContextHolder.getCurrentTabId(), which TabForge keeps set for the duration of a tab-scoped request.

      Returns:
      the current tab id, or null when there is no active tab (e.g. outside a JSF request)
    • currentSessionId

      public String currentSessionId()
      Resolve the id of the HTTP session the caller is currently in.

      Used internally to scope the timeline per user session; reads the session id from the active FacesContext without forcing a session to be created.

      Returns:
      the current session id, or null when there is no active JSF request/session