Skip to content

[GSoC POC] ApiClient refactor + IAIAdapter interface — AI Integration proposal#1239

Draft
7vignesh wants to merge 7 commits intoRocketChat:developfrom
7vignesh:poc/gsoc-2026-api-client-ai-adapter
Draft

[GSoC POC] ApiClient refactor + IAIAdapter interface — AI Integration proposal#1239
7vignesh wants to merge 7 commits intoRocketChat:developfrom
7vignesh:poc/gsoc-2026-api-client-ai-adapter

Conversation

@7vignesh
Copy link

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)

  • Introduces ApiClient class that centralizes auth header construction
  • Eliminates the repeated 5-line X-Auth-Token / X-User-Id block found
    across 30 methods in EmbeddedChatApi.ts
  • Adds RCApiError for normalized, typed error responses
  • Migrates 4 representative methods as proof: channelInfo, sendMessage,
    deleteMessage, getCommandsList
  • getCommandsList previously had zero error handling — now safely covered

Task 2 — AI Adapter System (packages/api + packages/react)

  • Adds IAIAdapter interface with suggestReply, summarizeThread,
    and optional moderateMessage
  • Adds MockAIAdapter for local testing without any API key
  • Adds optional aiAdapter prop to <EmbeddedChat> — zero breaking changes
  • Threads aiAdapter through RCInstanceProvider context
  • Adds useAIAdapter hook for clean consumption in any child component
  • Wires suggestion chips into ChatInput — visible when adapter is present,
    invisible when not

Files Changed

File Change
packages/api/src/ApiClient.ts New — ApiClient + RCApiError
packages/api/src/ai/IAIAdapter.ts New — interface + RCMessage type
packages/api/src/ai/MockAIAdapter.ts New — stub implementation
packages/api/src/index.ts Export new classes
packages/api/src/EmbeddedChatApi.ts Add apiClient property, migrate 4 methods
packages/react/src/views/EmbeddedChat.js Add aiAdapter prop + context
packages/react/src/context/RCInstance.js Update JSDoc
packages/react/src/hooks/useAIAdapter.js New — hook
packages/react/src/views/ChatInput/ChatInput.js Wire suggestion chips
packages/react/src/views/ChatInput/ChatInput.styles.js Theme-aware chip styles

Related

Feedback welcome — especially on the IAIAdapter interface design and
whether the context threading approach fits the existing architecture.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant