[GSoC POC] ApiClient refactor + IAIAdapter interface — AI Integration proposal#1239
Draft
7vignesh wants to merge 7 commits intoRocketChat:developfrom
Draft
[GSoC POC] ApiClient refactor + IAIAdapter interface — AI Integration proposal#12397vignesh wants to merge 7 commits intoRocketChat:developfrom
7vignesh wants to merge 7 commits intoRocketChat:developfrom
Conversation
…r handling - Adds ApiClient class to packages/api/src/ApiClient.ts - Centralizes X-Auth-Token and X-User-Id header construction - Adds RCApiError for normalized error responses - Adds concurrency-safe token refresh via refreshPromise lock - Replaces the repeated 5-line auth block pattern found across 30 methods
- Migrates channelInfo, sendMessage, deleteMessage, getCommandsList - getCommandsList previously had no try/catch — now safely handled by ApiClient - Each migrated method reduces from ~15 lines to 1 line - Remaining 26 methods to be migrated during GSoC coding period
- Adds packages/api/src/ai/IAIAdapter.ts with RCMessage type - Defines suggestReply, summarizeThread, and optional moderateMessage - Adds MockAIAdapter with stub implementations for local testing - Interface is minimal and extensible — any AI provider can implement it - Exports IAIAdapter, RCMessage, MockAIAdapter from package index
- Adds aiAdapter prop to EmbeddedChat.js (optional, defaults to null) - Threads aiAdapter through RCInstanceProvider context - Adds useAIAdapter hook in packages/react/src/hooks/useAIAdapter.js - Hook exposes: isAIEnabled, suggestions, summary, isLoading, getSuggestions, getThreadSummary - Zero breaking changes — existing integrations unaffected when aiAdapter is omitted
… present - Calls useAIAdapter hook inside ChatInput component - Renders suggestion chips above input only when isAIEnabled and isInputFocused - Chips hide on blur, reappear on focus, prevent default on click to keep focus - Updated all Storybook stories to demo the feature with MockAIAdapter - Fully conditional — UI is identical to current when no adapter is provided
…, theme suggestion chips
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.
Overview
This PR is a Proof of Concept submitted as part of my GSoC 2026 proposal
for the AI Integration for EmbeddedChat project. It is not intended for
merging as-is — it demonstrates technical feasibility and my understanding
of the codebase.
What This POC Covers
Task 1 — ApiClient Wrapper (
packages/api)ApiClientclass that centralizes auth header constructionX-Auth-Token/X-User-Idblock foundacross 30 methods in
EmbeddedChatApi.tsRCApiErrorfor normalized, typed error responseschannelInfo,sendMessage,deleteMessage,getCommandsListgetCommandsListpreviously had zero error handling — now safely coveredTask 2 — AI Adapter System (
packages/api+packages/react)IAIAdapterinterface withsuggestReply,summarizeThread,and optional
moderateMessageMockAIAdapterfor local testing without any API keyaiAdapterprop to<EmbeddedChat>— zero breaking changesaiAdapterthroughRCInstanceProvidercontextuseAIAdapterhook for clean consumption in any child componentChatInput— visible when adapter is present,invisible when not
Files Changed
packages/api/src/ApiClient.tspackages/api/src/ai/IAIAdapter.tspackages/api/src/ai/MockAIAdapter.tspackages/api/src/index.tspackages/api/src/EmbeddedChatApi.tspackages/react/src/views/EmbeddedChat.jspackages/react/src/context/RCInstance.jspackages/react/src/hooks/useAIAdapter.jspackages/react/src/views/ChatInput/ChatInput.jspackages/react/src/views/ChatInput/ChatInput.styles.jsRelated