Giao diện
@digiforce-nc/plugin-ai
Plugin tích hợp AI vào hệ thống — kết nối LLM providers, tạo AI bots, quản lý tools/skills, hỗ trợ MCP clients, và tích hợp workflow.
Plugin này làm gì?
Plugin cung cấp nền tảng AI toàn diện: đăng ký nhiều LLM provider (OpenAI, Anthropic, Google, Ollama), tạo AI bots với personality và tools tùy chỉnh, kết nối MCP servers, và tích hợp vào workflow engine.
Bốn nhiệm vụ chính
| # | Nhiệm vụ | Chi tiết |
|---|---|---|
| 1 | LLM Provider Registry | Đăng ký, cấu hình nhiều LLM provider (API key, model, params) |
| 2 | AI Bots & Chat | Tạo bots với system prompt, gán tools/skills, chat conversations |
| 3 | MCP & Tools | Kết nối MCP servers, quản lý AI tools mở rộng |
| 4 | Workflow | AI bot trigger + LLM instruction node trong workflow |
Kiến trúc
Luồng chat với AI bot
LLM Provider Registry
| Provider | Models | SDK |
|---|---|---|
| OpenAI | GPT-4o, GPT-4, GPT-3.5 | @langchain/openai |
| Anthropic | Claude 3.5, Claude 3 | @langchain/anthropic |
| Gemini Pro, Gemini Flash | @langchain/google-genai | |
| Ollama | Llama, Mistral, CodeLlama... | @langchain/ollama |
Database - 12+ collections
| Collection | Chứa gì |
|---|---|
llmServices | Cấu hình LLM provider (API key, base URL, model) |
aiBots | Định nghĩa bot (system prompt, model, tools) |
aiConversations / aiMessages | Phiên chat và tin nhắn |
aiSettings | Cấu hình AI toàn cục |
aiSkills / aiContextDatasource | RAG skills, datasource connectors |
aiMcpClients / aiTools | MCP connections và tool definitions |
aiFiles | Files đính kèm trong chat |
lc-checkpoints | LangChain checkpoints (agent state) |
users-ai-bots | Liên kết user - bot (M2M) |
Vòng đời plugin
Workflow Integration
| Thành phần | Vai trò |
|---|---|
| AI Bot Trigger | Workflow kích hoạt khi user gửi message cho bot |
| LLM Instruction Node | Node gọi LLM với prompt tùy chỉnh, nhận kết quả |
Ví dụ sử dụng API
Cấu hình LLM provider
typescript
await agent.resource('llmServices').create({
values: {
name: 'openai-main',
provider: 'openai',
apiKey: 'sk-...',
defaultModel: 'gpt-4o',
},
});Tạo AI bot
typescript
await agent.resource('aiBots').create({
values: {
name: 'Support Bot',
systemPrompt: 'Bạn là trợ lý hỗ trợ khách hàng...',
llmServiceId: 1,
model: 'gpt-4o',
},
});Chat với bot
typescript
const conv = await agent.resource('aiConversations').create({
values: { botId: 1 },
});
await agent.resource('aiMessages').create({
values: {
conversationId: conv.body.data.id,
content: 'Làm sao để đặt hàng?',
role: 'user',
},
});Thành phần client
| Thành phần | Mô tả |
|---|---|
AIBotsProvider | Context provider cho AI bots state |
ChatInterface | Giao diện chat với AI bot |
LLMSettings | Trang cấu hình LLM providers |
MCPSettings | Trang cấu hình MCP clients |
BotManager | Trang quản lý AI bots |
WorkflowLLMNode | UI cho LLM node trong workflow editor |
Dependencies
| Package | Vai trò |
|---|---|
langchain, @langchain/openai, @langchain/anthropic, @langchain/google-genai, @langchain/ollama | LLM orchestration + providers |
zustand | State management cho chat UI |
react-markdown | Render markdown trong responses |