feat(gateway): add context provider abstraction with LINE buffered context#1165
feat(gateway): add context provider abstraction with LINE buffered context#1165iamninihuang wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
|
per discussion here https://discord.com/channels/1491295327620169908/1517915941269147850/1517919091363545169 let's consider to build an all-platform context provider feature instead of LINE only. |
35125ce to
51af031
Compare
|
Updated this PR based on the cross-platform direction discussed in Discord. Main changes:
Local validation:
This keeps the current PR useful for LINE while leaving Discord/Slack/Teams/Google Chat API-backed providers as follow-up work. |
|
LGTM ✅ — Well-structured context provider abstraction with solid test coverage and conservative defaults. What This PR DoesSolves the "lost context" problem in mention-gated group chats (especially LINE) by adding a gateway-level How It Works
Findings
What's Good (🟢)
Baseline Check
|
Summary
This PR refactors the original LINE-only group context buffer into a gateway-level ContextProvider foundation, with LINE using the first buffered implementation.
Problem: mention-gated chatrooms can lose the conversation that happened before someone finally mentions the bot. LINE cannot fetch historical group messages from the platform API, so the only practical way to recover that context is to observe recent non-triggering messages locally and inject them when the bot is mentioned.
What changed:
gateway/src/context/withContextProvider,ContextScope,ContextMessage, config, and shared context injection formatting.BufferedContextProviderfor webhook-observed platforms such as LINE, Telegram, WeChat/WeCom, and fallback cases.ApiFetchContextProviderskeleton for platforms that can fetch history from native APIs such as Discord, Slack, Teams, or Google Chat spaces.Prior Art And Design Input
Community discussion: https://discord.com/channels/1491295327620169908/1517816542610460825
This design follows the direction suggested by Pahud: make the feature cross-platform instead of LINE-only.
Observed prior art:
Scope
Included:
Not included:
/history100command syntax.Configuration
Defaults are intentionally conservative:
enabled = falsettl = 24hmax_messages = 50max_chars = 8000LINE-specific env vars can override gateway defaults:
LINE_GROUP_CONTEXT_ENABLEDLINE_GROUP_CONTEXT_TTL_HOURSLINE_GROUP_CONTEXT_MAX_MESSAGESLINE_GROUP_CONTEXT_MAX_CHARSLINE_CONTEXT_BOT_IDBefore / After
Before:
After:
Testing
Ran locally in
gateway:cargo test- 272 passedcargo clippy -- -D warnings- passedCovered by tests: