feat(plugins): expose engine.getChatHistory to plugins (#609)#613
Merged
Conversation
Add a getChatHistory(sessionId, chatId, limit?, includeMedia?) method to PluginEngineReadCapability, bound in the loader through the same resolveEngineRead gate as the other engine reads (engine:read permission + active session). The limit is clamped inline to 100 (the REST non-deep ceiling) so an untrusted plugin can't request an unbounded fetch; both message directions are returned. Host-side prerequisite for the chatwoot-adapter history backfill.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #609 (initial history sync). Host-side prerequisite for the chatwoot-adapter history backfill.
Summary
Adds
getChatHistory(sessionId, chatId, limit?, includeMedia?)toPluginEngineReadCapability, so a plugin can read recent messages for a chat (both directions) — the read a backfill needs. It sits alongside the existing engine reads (getChats,getContacts, …).Gating & bounds
resolveEngineReadgate as the other engine reads: requires theengine:readpermission and an active session for the plugin.limitis clamped inline to 100 (the REST non-deep ceiling) so an untrusted plugin cannot request an unbounded history fetch. Defaults to 50; a non-positive value clamps to 1.Tests
Delegation with the limit clamped (500 → 100), the default/clamp-to-1 cases, and a permission denial (no
engine:read→PluginCapabilityError, engine never resolved). Full backend suite green (1909 tests); lint and build clean.Additive and backward-compatible. Targeted for the next patch (0.8.5), which the
chatwoot-adapterbackfill will pin.