
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
ai-chat-html-exporter
Advanced tools
A JavaScript/TypeScript library that intercepts OpenAI chat conversations and automatically exports them as beautiful HTML files
一个用于拦截 OpenAI 聊天对话并自动导出为美观 HTML 文件的 JavaScript/TypeScript 库。
这是 ai-chat-html-exporter 项目的 JavaScript/TypeScript 实现。如果您在寻找 Python 版本,请查看根目录。
npm install ai-chat-html-exporter
或者使用 yarn:
yarn add ai-chat-html-exporter
import OpenAI from 'openai';
import { createChatExporterOpenAI } from 'ai-chat-html-exporter';
// 创建带有导出功能的 OpenAI 客户端
const openai = createChatExporterOpenAI(OpenAI, {
apiKey: process.env.OPENAI_API_KEY,
});
// 正常使用 OpenAI API,对话会自动导出为 HTML
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [
{ role: 'user', content: 'Hello, how are you?' }
],
});
console.log(response.choices[0].message.content);
const OpenAI = require('openai');
const { createChatExporterOpenAI } = require('ai-chat-html-exporter');
const openai = createChatExporterOpenAI(OpenAI, {
apiKey: process.env.OPENAI_API_KEY,
});
<script src="https://unpkg.com/ai-chat-html-exporter/dist/index.umd.js"></script>
<script>
const openai = AiChatHtmlExporter.createChatExporterOpenAI(OpenAI, {
apiKey: 'your-api-key',
});
</script>
interface ExporterOptions {
outputDir?: string; // 输出目录,默认 'logs'
enableFileOutput?: boolean; // 是否启用文件输出,默认 true
customStyles?: string; // 自定义 CSS 样式
}
const openai = createChatExporterOpenAI(OpenAI, {
apiKey: process.env.OPENAI_API_KEY,
}, {
outputDir: 'chat-exports',
enableFileOutput: true,
customStyles: `
.message { border-radius: 15px; }
.user { background: #e3f2fd; }
`
});
import { OpenaiChatHtmlExporter } from 'ai-chat-html-exporter';
const exporter = new OpenaiChatHtmlExporter({
outputDir: 'my-exports',
customStyles: '/* 自定义样式 */'
});
// 手动处理消息
exporter.processUserMessages([
{ role: 'user', content: 'Hello!' }
]);
// 处理 AI 响应
exporter.processAIResponse(response);
库完全支持 OpenAI 的流式响应:
const stream = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
// 对话会自动保存为 HTML 文件
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'What\'s the weather like?' }],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get weather information',
parameters: {
type: 'object',
properties: {
location: { type: 'string' }
}
}
}
}
]
});
// 工具调用信息会在 HTML 中完整展示
createChatExporterOpenAI(OpenAIClass, config, exporterOptions?)创建带有对话导出功能的 OpenAI 客户端。
参数:
OpenAIClass: OpenAI 客户端类config: OpenAI 配置对象exporterOptions: 可选的导出器配置返回:
OpenaiChatHtmlExporter对话导出器类。
构造函数:
constructor(options?: ExporterOptions)主要方法:
processUserMessages(messages, tools?): 处理用户消息processAIResponse(response): 处理 AI 响应processStreamCompletionResponse(content, toolCalls): 处理流式响应logError(errorMessage): 记录错误信息生成的 HTML 文件包含:
这个 JavaScript/TypeScript 库是 ai-chat-html-exporter 项目的前端实现。该项目同时提供:
两个版本生成相同格式的 HTML 文件,您可以根据项目需求选择合适的版本。
# 进入 JavaScript 包目录
cd packages/javascript
# 安装依赖
npm install
# 构建
npm run build
# 开发模式
npm run dev
# 验证构建
npm run validate
查看 examples/ 目录获取更多使用示例:
basic-usage.js - 基础用法示例typescript-usage.ts - TypeScript 高级示例MIT License - 详见项目根目录的 LICENSE 文件。
欢迎提交 Issue 和 Pull Request!请参考项目根目录的贡献指南。
FAQs
A JavaScript/TypeScript library that intercepts OpenAI chat conversations and automatically exports them as beautiful HTML files
We found that ai-chat-html-exporter 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
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.