🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@deepracticex/ai-chat

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deepracticex/ai-chat - npm Package Compare versions

Comparing version
0.1.2
to
0.2.0
+13
-17
dist/core/AIChat.js

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -11,12 +10,10 @@ * AIChat 主协调器类 - 简化后的设计

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIChat = void 0;
const types_1 = require("../types");
const StreamUtils_1 = require("../streaming/StreamUtils");
const ToolExecutionManager_1 = require("../tools/ToolExecutionManager");
const HttpClient_1 = require("../http/HttpClient");
import { AIChatError } from '../types';
import { createErrorChunk } from '../streaming/StreamUtils';
import { ToolExecutionManager } from '../tools/ToolExecutionManager';
import { HttpClient } from '../http/HttpClient';
/**
* AIChat类 - 简化的AI聊天协调器
*/
class AIChat {
export class AIChat {
/**

@@ -28,9 +25,9 @@ * 构造函数 - 简单配置接受

if (!config) {
throw new types_1.AIChatError('Config is required', 'INVALID_CONFIG');
throw new AIChatError('Config is required', 'INVALID_CONFIG');
}
if (!config.baseUrl) {
throw new types_1.AIChatError('baseUrl is required', 'INVALID_CONFIG');
throw new AIChatError('baseUrl is required', 'INVALID_CONFIG');
}
if (!config.model) {
throw new types_1.AIChatError('model is required', 'INVALID_CONFIG');
throw new AIChatError('model is required', 'INVALID_CONFIG');
}

@@ -40,5 +37,5 @@ // 存储配置

// 创建HTTP客户端
this.httpClient = new HttpClient_1.HttpClient(config);
this.httpClient = new HttpClient(config);
// 初始化工具管理器
this.toolManager = new ToolExecutionManager_1.ToolExecutionManager();
this.toolManager = new ToolExecutionManager();
}

@@ -65,3 +62,3 @@ /**

if (!messages || messages.length === 0) {
throw new types_1.AIChatError('Messages array is required and cannot be empty', 'INVALID_INPUT');
throw new AIChatError('Messages array is required and cannot be empty', 'INVALID_INPUT');
}

@@ -78,3 +75,3 @@ // 如果有工具调用处理器,注册到工具管理器

// 流式错误处理 - yield错误chunk
yield (0, StreamUtils_1.createErrorChunk)(error);
yield createErrorChunk(error);
}

@@ -310,3 +307,3 @@ }

if (chunk.error) {
throw new types_1.AIChatError(chunk.error, 'STREAM_ERROR');
throw new AIChatError(chunk.error, 'STREAM_ERROR');
}

@@ -331,2 +328,1 @@ if (chunk.done) {

}
exports.AIChat = AIChat;

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -6,6 +5,4 @@ * 简单的HTTP客户端 - 直接处理OpenAI兼容的API请求

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpClient = void 0;
const types_1 = require("../types");
class HttpClient {
import { HttpError } from '../types';
export class HttpClient {
constructor(config) {

@@ -37,3 +34,3 @@ this.config = config;

if (!response.body) {
throw new types_1.HttpError('Response body is null for streaming request');
throw new HttpError('Response body is null for streaming request');
}

@@ -107,5 +104,5 @@ // 处理服务器发送事件 (SSE) 流

if (error instanceof Error && error.name === 'AbortError') {
throw new types_1.HttpError(`Request timeout after ${this.timeout}ms`);
throw new HttpError(`Request timeout after ${this.timeout}ms`);
}
throw new types_1.HttpError(`Request failed: ${error instanceof Error ? error.message : String(error)}`);
throw new HttpError(`Request failed: ${error instanceof Error ? error.message : String(error)}`);
}

@@ -127,5 +124,4 @@ }

}
throw new types_1.HttpError(errorMessage, response.status);
throw new HttpError(errorMessage, response.status);
}
}
exports.HttpClient = HttpClient;

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -6,34 +5,14 @@ * @ai-chat/core - 简化后的主入口

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = exports.createErrorChunk = exports.HttpClient = exports.ToolExecutionManager = exports.AIChat = void 0;
// ============== 主要类导出 ==============
var AIChat_1 = require("./core/AIChat");
Object.defineProperty(exports, "AIChat", { enumerable: true, get: function () { return AIChat_1.AIChat; } });
export { AIChat } from './core/AIChat';
// ============== 工具导出 ==============
var ToolExecutionManager_1 = require("./tools/ToolExecutionManager");
Object.defineProperty(exports, "ToolExecutionManager", { enumerable: true, get: function () { return ToolExecutionManager_1.ToolExecutionManager; } });
export { ToolExecutionManager } from './tools/ToolExecutionManager';
// ============== HTTP 客户端导出 ==============
var HttpClient_1 = require("./http/HttpClient");
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_1.HttpClient; } });
export { HttpClient } from './http/HttpClient';
// ============== 流处理导出 ==============
var StreamUtils_1 = require("./streaming/StreamUtils");
Object.defineProperty(exports, "createErrorChunk", { enumerable: true, get: function () { return StreamUtils_1.createErrorChunk; } });
export { createErrorChunk } from './streaming/StreamUtils';
// ============== 类型导出 ==============
__exportStar(require("./types"), exports);
export * from './types';
// ============== 版本信息 ==============
exports.version = '0.2.0'; // 版本升级,表示重大重构
export const version = '0.2.0'; // 版本升级,表示重大重构
// ============== 包状态 ==============

@@ -40,0 +19,0 @@ // 重构完成!新特性:

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -7,4 +6,2 @@ * 流式响应处理工具

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createErrorChunk = createErrorChunk;
/**

@@ -16,3 +13,3 @@ * 创建错误chunk

*/
function createErrorChunk(error) {
export function createErrorChunk(error) {
const errorMessage = error instanceof Error

@@ -19,0 +16,0 @@ ? error.message

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -7,8 +6,6 @@ * 工具执行管理器

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolExecutionManager = void 0;
/**
* 工具执行管理器
*/
class ToolExecutionManager {
export class ToolExecutionManager {
constructor() {

@@ -150,2 +147,1 @@ this.state = {

}
exports.ToolExecutionManager = ToolExecutionManager;

@@ -1,2 +0,1 @@

"use strict";
/**

@@ -6,6 +5,4 @@ * 简化的 AI Chat 类型定义

*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolError = exports.HttpError = exports.AIChatError = void 0;
// ============== 错误类型 ==============
class AIChatError extends Error {
export class AIChatError extends Error {
constructor(message, code, details) {

@@ -18,4 +15,3 @@ super(message);

}
exports.AIChatError = AIChatError;
class HttpError extends AIChatError {
export class HttpError extends AIChatError {
constructor(message, status, details) {

@@ -27,4 +23,3 @@ super(message, 'HTTP_ERROR', details);

}
exports.HttpError = HttpError;
class ToolError extends AIChatError {
export class ToolError extends AIChatError {
constructor(message, toolName, details) {

@@ -36,2 +31,1 @@ super(message, 'TOOL_ERROR', details);

}
exports.ToolError = ToolError;
{
"name": "@deepracticex/ai-chat",
"version": "0.1.2",
"version": "0.2.0",
"description": "A focused AI chat client for handling AI requests and tool calling in Node.js applications",
"type": "module",
"main": "dist/index.js",

@@ -6,0 +7,0 @@ "types": "dist/index.d.ts",