Skip to content

Conversation

@3coins
Copy link
Contributor

@3coins 3coins commented Oct 27, 2025

Still working through some of the finer things. Here is the overall strategy:

  1. A new API observe_notebook_activity(user, callback) is provided that start the tracking for the current active room for the user. Callback receives the last_active_cell id, and notebook_path.
  2. Tracks ydoc updates (ycells) to record last edit times for a specific room. This can be tweaked to look for specific changes, currently tracking any change to the cells.
  3. Tracks doc awareness for tracking the active cell and and calls the observer if there were any edits and the active cell has changed. Depends on jupyterlab-notebook-awareness for getting active cell and notebook path.
  4. Tracks the global awareness to keep track of the active document for the user, so registers new observers for the relevant room, also unregisters observers for the previous room.

Todos:

  1. Fix get_global_awareness, and room_id_from_path for non-jsd environments, or handle it appropriately in the observer registration.
  2. Handle ydoc resets (renaming files breaks the flow currently)
  3. Start tracking global awareness only when the first observer is registered.
  4. Tweak tracking of cell updates, for example, should adding an empty cell be considered a change?
jai-router-notebook-observers.mp4

Fixes #8

@3coins 3coins added the enhancement New feature or request label Oct 27, 2025
@Zsailer
Copy link

Zsailer commented Oct 28, 2025

@3coins can these callback be async? Briefly browsed the code, but looks like it expects synchronous callbacks?

@3coins
Copy link
Contributor Author

3coins commented Oct 28, 2025

@3coins can these callback be async? Briefly browsed the code, but looks like it expects synchronous callbacks?

That's correct, but we can change that so both are supported.

3coins pushed a commit that referenced this pull request Nov 2, 2025
This change allows all callback registration methods to accept both
synchronous and asynchronous callbacks. The router will automatically
detect if a callback is async using asyncio.iscoroutinefunction() and
schedule it as a task if needed.

This addresses the comment in PR #13 requesting async callback support.

Changes:
- Add asyncio import
- Add _invoke_callback() helper method to handle both sync and async
- Update all callback invocation sites to use the helper:
  - _notify_notebook_activity_observers
  - _notify_slash_cmd_observers
  - _notify_chat_init_observers
  - _notify_msg_observers
  - _on_chat_reset
  - _on_notebook_reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observer API for background agent/persona activation

2 participants