feat: add v3 chat output listener API#1442
Conversation
cubicj
left a comment
There was a problem hiding this comment.
The listener API direction looks useful, but I found one streaming-path ordering issue.
In the streaming path, the listener runs before the host applies the inlay result and writes currentChat back to the DB. This means plugins receive the pre-inlay chat snapshot, and any changes persisted with setChatToIndex can be overwritten by that later host-side write.
Could you check the listener ordering there?
684965e to
cf3ec61
Compare
cf3ec61 to
cab7a8a
Compare
|
Thanks for the review. I rechecked the listener ordering in the streaming path and updated it in the latest commit. I moved the v3 output listener in the streaming path to run after both the sync and async The non-streaming path already ran the listener after inlay processing and the Lua I also updated the API docs to describe the new lifecycle, and wired v3 chat listeners to unregister automatically when the plugin unloads. Verification:
|
cubicj
left a comment
There was a problem hiding this comment.
Verified the updated listener lifecycle. The streaming path now runs the listener after Lua output and sync/async inlay writes, so the previous stale write-back concern is addressed.
Check, tests, and build pass locally.
Approving — thanks for the contribution!
PR Checklist
Summary
Adds
addRisuChatListener('output', fn)andremoveRisuChatListener('output', fn)for v3 plugins.This lets plugins react after a model output has been committed to the chat, at the same lifecycle point as the existing Lua
outputtrigger.Related Issues
None.
Changes
chatOutputlistener set to the plugin API runtime.addRisuChatListenerandremoveRisuChatListener.outputtrigger.characterIndex,chatIndex, andmessageIndexto the listener.Impact
Additive only. Existing plugins are unaffected unless they opt in to the new listener API.
This gives plugin authors a lifecycle point for starting background work after the main chat response is already committed. For example, a plugin can let the user read the generated message immediately, then update related chat data later through existing setter APIs when its background work completes.
The listener receives snapshots of the current character and chat, matching the existing v3
getCharacterFromIndexandgetChatFromIndexbehavior. Plugins that need to persist changes can use existing setter APIs such assetChatToIndex.Additional Notes
Listener errors are caught and logged so one plugin listener cannot break the chat flow.
Testing
pnpm checkpnpm test