
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
lan-chat-interface
Advanced tools
一个功能丰富、易于使用的聊天界面组件库,基于 React 和 TypeScript 构建,支持实时聊天、Markdown 渲染、代码高亮等功能。
npm install lan-chat-interface
import React from "react";
import { ChatInterface } from "lan-chat-interface";
import "lan-chat-interface/styles.css";
const App: React.FC = () => {
return (
<div className="h-screen w-full">
<ChatInterface
apiRoute="https://your-sse-endpoint.com/chat"
method="POST"
title="AI 聊天助手"
initialMessage="你好,我是 AI 助手,有什么可以帮你?"
/>
</div>
);
};
export default App;
import React from "react";
import { ChatInterface } from "lan-chat-interface";
import "lan-chat-interface/styles.css";
import { Message } from "lan-chat-interface/types";
const App: React.FC = () => {
// 历史消息记录
const initialHistory: Message[] = [
{
id: "1",
role: "user",
content: "你好,介绍一下自己",
},
{
id: "2",
role: "assistant",
content: "你好!我是一个基于人工智能的聊天助手,很高兴为您服务。",
},
];
return (
<div className="h-screen w-full">
<ChatInterface
apiRoute="https://your-sse-endpoint.com/chat"
title="AI 聊天助手"
initialHistory={initialHistory}
/>
</div>
);
};
export default App;
import React from "react";
import { ChatInterface } from "lan-chat-interface";
import "lan-chat-interface/styles.css";
import { BodyBuilderFn } from "lan-chat-interface/types";
const App: React.FC = () => {
// 自定义请求体构建函数
const customBodyBuilder: BodyBuilderFn = (payload) => {
return {
prompt: payload.currentMessage,
conversation_history: payload.history.map((msg) => ({
role: msg.role,
content: msg.content,
})),
temperature: 0.7,
max_tokens: 500,
};
};
return (
<div className="h-screen w-full">
<ChatInterface
apiRoute="https://your-sse-endpoint.com/chat"
method="POST"
title="AI 聊天助手"
initialMessage="你好,我是 AI 助手,有什么可以帮你?"
bodyBuilder={customBodyBuilder}
/>
</div>
);
};
export default App;
import React from "react";
import { ChatInterface } from "lan-chat-interface";
import "lan-chat-interface/styles.css";
const App: React.FC = () => {
return (
<div className="h-screen w-full">
<ChatInterface
apiRoute="https://your-sse-endpoint.com/chat"
method="POST"
title="我的专属 AI 助手"
initialMessage="你好,我是你的专属 AI 助手,有什么可以帮你?"
userAvatar="https://example.com/user-avatar.png"
aiAvatar="https://example.com/ai-avatar.png"
userName="用户"
aiName="AI 助手"
placeholder="请输入您的问题..."
/>
</div>
);
};
export default App;
import React, { useState } from "react";
import { ChatInterface } from "lan-chat-interface";
import "lan-chat-interface/styles.css";
const App: React.FC = () => {
const [isDisabled, setIsDisabled] = useState(false);
return (
<div className="h-screen w-full">
<div className="p-4 bg-gray-100">
<button
onClick={() => setIsDisabled(!isDisabled)}
className="px-4 py-2 bg-blue-500 text-white rounded"
>
{isDisabled ? "启用输入" : "禁用输入"}
</button>
</div>
<ChatInterface
apiRoute="https://your-sse-endpoint.com/chat"
method="POST"
title="AI 聊天助手"
initialMessage="你好,我是 AI 助手,有什么可以帮你?"
disabled={isDisabled}
/>
</div>
);
};
export default App;
主聊天界面组件,包含消息列表和输入区域,内部集成了 SSE 实时通信功能。
| 属性名 | 类型 | 描述 |
|---|---|---|
apiRoute | string | SSE 服务器接口地址 |
method | "GET" | "POST" | 请求方法(默认:GET) |
initialMessage | string | 初始欢迎消息(可选) |
title | string | 聊天窗口标题(可选) |
className | string | 自定义样式类名(可选) |
initialHistory | Message[] | 初始历史消息记录(可选) |
bodyBuilder | BodyBuilderFn | 自定义请求体构建函数(可选) |
userAvatar | string | 用户头像 URL(可选) |
aiAvatar | string | AI 头像 URL(可选) |
userName | string | 用户名称(可选,默认:"You") |
aiName | string | AI 名称(可选,默认:"AI Assistant") |
disabled | boolean | 全局禁用输入(可选,默认:false) |
placeholder | string | 输入框占位符(可选,默认:"输入消息...") |
单条消息组件。
| 属性名 | 类型 | 描述 |
|---|---|---|
message | Message | 消息对象 |
userAvatar | string | 用户头像 URL(可选) |
aiAvatar | string | AI 头像 URL(可选) |
userName | string | 用户名称(可选,默认:"You") |
aiName | string | AI 名称(可选,默认:"AI Assistant") |
代码块组件,支持语法高亮和复制功能。
| 属性名 | 类型 | 描述 |
|---|---|---|
code | string | 代码内容 |
language | string | 编程语言(可选) |
聊天输入框组件。
| 属性名 | 类型 | 描述 |
|---|---|---|
value | string | 输入框内容 |
onChange | (e: React.ChangeEvent<HTMLTextAreaElement>) => void | 内容变化回调 |
onSend | () => void | 发送按钮点击回调 |
isLoading | boolean | 是否加载中(可选) |
disabled | boolean | 是否禁用输入(可选,默认:false) |
placeholder | string | 占位符(可选,默认:"输入消息...") |
Markdown 渲染组件。
| 属性名 | 类型 | 描述 |
|---|---|---|
content | string | Markdown 内容 |
用于处理 Server-Sent Events 实时聊天的 Hook(内部使用)。
该 Hook 已被 ChatInterface 组件内部集成,通常不需要直接使用。如果需要自定义聊天逻辑,可以查看源代码实现。
用于复制文本到剪贴板的 Hook。
| 返回值 | 类型 | 描述 |
|---|---|---|
copyToClipboard | (text: string) => Promise<boolean> | 复制文本函数 |
isCopied | boolean | 是否已复制 |
npm install
npm run dev
npm run build
npm run type-check
interface Message {
id: string;
role: "user" | "assistant";
content: string;
[key: string]: any;
}
type BodyBuilderFn = (payload: {
// 当前用户的消息内容
currentMessage: string;
// 历史消息(包含id)
history: Message[];
}) => any;
MIT
FAQs
A React chat interface component library
The npm package lan-chat-interface receives a total of 0 weekly downloads. As such, lan-chat-interface popularity was classified as not popular.
We found that lan-chat-interface demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.