@agenticc/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +370 -0
- package/README.zh-CN.md +372 -0
- package/dist/audit/index.d.ts +9 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +9 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/logger.d.ts +211 -0
- package/dist/audit/logger.d.ts.map +1 -0
- package/dist/audit/logger.js +268 -0
- package/dist/audit/logger.js.map +1 -0
- package/dist/audit/query.d.ts +164 -0
- package/dist/audit/query.d.ts.map +1 -0
- package/dist/audit/query.js +250 -0
- package/dist/audit/query.js.map +1 -0
- package/dist/conversation/context-builder.d.ts +119 -0
- package/dist/conversation/context-builder.d.ts.map +1 -0
- package/dist/conversation/context-builder.js +252 -0
- package/dist/conversation/context-builder.js.map +1 -0
- package/dist/conversation/index.d.ts +10 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +10 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/message-store.d.ts +231 -0
- package/dist/conversation/message-store.d.ts.map +1 -0
- package/dist/conversation/message-store.js +404 -0
- package/dist/conversation/message-store.js.map +1 -0
- package/dist/conversation/session.d.ts +201 -0
- package/dist/conversation/session.d.ts.map +1 -0
- package/dist/conversation/session.js +285 -0
- package/dist/conversation/session.js.map +1 -0
- package/dist/core/agent.d.ts +277 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +674 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/agentic-loop.d.ts +98 -0
- package/dist/core/agentic-loop.d.ts.map +1 -0
- package/dist/core/agentic-loop.js +496 -0
- package/dist/core/agentic-loop.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/intent-parser.d.ts +101 -0
- package/dist/core/intent-parser.d.ts.map +1 -0
- package/dist/core/intent-parser.js +221 -0
- package/dist/core/intent-parser.js.map +1 -0
- package/dist/core/plan-generator.d.ts +133 -0
- package/dist/core/plan-generator.d.ts.map +1 -0
- package/dist/core/plan-generator.js +294 -0
- package/dist/core/plan-generator.js.map +1 -0
- package/dist/core/plugin-manager.d.ts +120 -0
- package/dist/core/plugin-manager.d.ts.map +1 -0
- package/dist/core/plugin-manager.js +369 -0
- package/dist/core/plugin-manager.js.map +1 -0
- package/dist/core/response-handler.d.ts +141 -0
- package/dist/core/response-handler.d.ts.map +1 -0
- package/dist/core/response-handler.js +384 -0
- package/dist/core/response-handler.js.map +1 -0
- package/dist/core/tool-executor.d.ts +143 -0
- package/dist/core/tool-executor.d.ts.map +1 -0
- package/dist/core/tool-executor.js +354 -0
- package/dist/core/tool-executor.js.map +1 -0
- package/dist/core/tool-registry.d.ts +133 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +252 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/chunker.d.ts +78 -0
- package/dist/knowledge/chunker.d.ts.map +1 -0
- package/dist/knowledge/chunker.js +233 -0
- package/dist/knowledge/chunker.js.map +1 -0
- package/dist/knowledge/embedder.d.ts +93 -0
- package/dist/knowledge/embedder.d.ts.map +1 -0
- package/dist/knowledge/embedder.js +205 -0
- package/dist/knowledge/embedder.js.map +1 -0
- package/dist/knowledge/index.d.ts +10 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +11 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/loaders/index.d.ts +10 -0
- package/dist/knowledge/loaders/index.d.ts.map +1 -0
- package/dist/knowledge/loaders/index.js +10 -0
- package/dist/knowledge/loaders/index.js.map +1 -0
- package/dist/knowledge/loaders/markdown.d.ts +88 -0
- package/dist/knowledge/loaders/markdown.d.ts.map +1 -0
- package/dist/knowledge/loaders/markdown.js +205 -0
- package/dist/knowledge/loaders/markdown.js.map +1 -0
- package/dist/knowledge/loaders/yaml.d.ts +112 -0
- package/dist/knowledge/loaders/yaml.d.ts.map +1 -0
- package/dist/knowledge/loaders/yaml.js +368 -0
- package/dist/knowledge/loaders/yaml.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +144 -0
- package/dist/knowledge/retriever.d.ts.map +1 -0
- package/dist/knowledge/retriever.js +399 -0
- package/dist/knowledge/retriever.js.map +1 -0
- package/dist/knowledge/store.d.ts +146 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +420 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/llm/adapter.d.ts +194 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +42 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/adapters/anyrouter.d.ts +84 -0
- package/dist/llm/adapters/anyrouter.d.ts.map +1 -0
- package/dist/llm/adapters/anyrouter.js +372 -0
- package/dist/llm/adapters/anyrouter.js.map +1 -0
- package/dist/llm/adapters/claude.d.ts +66 -0
- package/dist/llm/adapters/claude.d.ts.map +1 -0
- package/dist/llm/adapters/claude.js +323 -0
- package/dist/llm/adapters/claude.js.map +1 -0
- package/dist/llm/adapters/index.d.ts +12 -0
- package/dist/llm/adapters/index.d.ts.map +1 -0
- package/dist/llm/adapters/index.js +12 -0
- package/dist/llm/adapters/index.js.map +1 -0
- package/dist/llm/adapters/mimo.d.ts +85 -0
- package/dist/llm/adapters/mimo.d.ts.map +1 -0
- package/dist/llm/adapters/mimo.js +316 -0
- package/dist/llm/adapters/mimo.js.map +1 -0
- package/dist/llm/adapters/openai.d.ts +53 -0
- package/dist/llm/adapters/openai.d.ts.map +1 -0
- package/dist/llm/adapters/openai.js +293 -0
- package/dist/llm/adapters/openai.js.map +1 -0
- package/dist/llm/adapters/qwen.d.ts +53 -0
- package/dist/llm/adapters/qwen.d.ts.map +1 -0
- package/dist/llm/adapters/qwen.js +299 -0
- package/dist/llm/adapters/qwen.js.map +1 -0
- package/dist/llm/adapters/siliconflow.d.ts +69 -0
- package/dist/llm/adapters/siliconflow.d.ts.map +1 -0
- package/dist/llm/adapters/siliconflow.js +331 -0
- package/dist/llm/adapters/siliconflow.js.map +1 -0
- package/dist/llm/index.d.ts +9 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +12 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/manager.d.ts +97 -0
- package/dist/llm/manager.d.ts.map +1 -0
- package/dist/llm/manager.js +337 -0
- package/dist/llm/manager.js.map +1 -0
- package/dist/test-utils/arbitraries.d.ts +230 -0
- package/dist/test-utils/arbitraries.d.ts.map +1 -0
- package/dist/test-utils/arbitraries.js +280 -0
- package/dist/test-utils/arbitraries.js.map +1 -0
- package/dist/test-utils/cleanup.d.ts +184 -0
- package/dist/test-utils/cleanup.d.ts.map +1 -0
- package/dist/test-utils/cleanup.js +282 -0
- package/dist/test-utils/cleanup.js.map +1 -0
- package/dist/test-utils/config.d.ts +80 -0
- package/dist/test-utils/config.d.ts.map +1 -0
- package/dist/test-utils/config.js +94 -0
- package/dist/test-utils/config.js.map +1 -0
- package/dist/test-utils/index.d.ts +10 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +36 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/mocks.d.ts +170 -0
- package/dist/test-utils/mocks.d.ts.map +1 -0
- package/dist/test-utils/mocks.js +281 -0
- package/dist/test-utils/mocks.js.map +1 -0
- package/dist/types/config.d.ts +170 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +120 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/knowledge.d.ts +95 -0
- package/dist/types/knowledge.d.ts.map +1 -0
- package/dist/types/knowledge.js +7 -0
- package/dist/types/knowledge.js.map +1 -0
- package/dist/types/loop.d.ts +148 -0
- package/dist/types/loop.d.ts.map +1 -0
- package/dist/types/loop.js +16 -0
- package/dist/types/loop.js.map +1 -0
- package/dist/types/plugin.d.ts +137 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +15 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/types/response.d.ts +186 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +99 -0
- package/dist/types/response.js.map +1 -0
- package/dist/types/streaming.d.ts +478 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +483 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/tool.d.ts +118 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +42 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/error.d.ts +22 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +36 -0
- package/dist/utils/error.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Registry
|
|
3
|
+
*
|
|
4
|
+
* Manages registration and retrieval of tools for the Agent.
|
|
5
|
+
* Validates tool definitions and provides Function Calling format conversion.
|
|
6
|
+
*
|
|
7
|
+
* @module core/tool-registry
|
|
8
|
+
*/
|
|
9
|
+
import { toolToDefinition } from '../types/tool.js';
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when tool registration fails
|
|
12
|
+
*/
|
|
13
|
+
export class ToolRegistrationError extends Error {
|
|
14
|
+
toolName;
|
|
15
|
+
reason;
|
|
16
|
+
constructor(message, toolName, reason) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.toolName = toolName;
|
|
19
|
+
this.reason = reason;
|
|
20
|
+
this.name = 'ToolRegistrationError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error thrown when a tool is not found
|
|
25
|
+
*/
|
|
26
|
+
export class ToolNotFoundError extends Error {
|
|
27
|
+
constructor(toolName) {
|
|
28
|
+
super(`Tool not found: ${toolName}`);
|
|
29
|
+
this.name = 'ToolNotFoundError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates a tool parameter definition
|
|
34
|
+
*/
|
|
35
|
+
function validateParameter(param, toolName) {
|
|
36
|
+
if (!param.name || typeof param.name !== 'string') {
|
|
37
|
+
throw new ToolRegistrationError(`Invalid parameter name in tool ${toolName}`, toolName, 'Parameter name must be a non-empty string');
|
|
38
|
+
}
|
|
39
|
+
const validTypes = ['string', 'number', 'boolean', 'object', 'array'];
|
|
40
|
+
if (!validTypes.includes(param.type)) {
|
|
41
|
+
throw new ToolRegistrationError(`Invalid parameter type "${param.type}" in tool ${toolName}`, toolName, `Parameter type must be one of: ${validTypes.join(', ')}`);
|
|
42
|
+
}
|
|
43
|
+
if (!param.description || typeof param.description !== 'string') {
|
|
44
|
+
throw new ToolRegistrationError(`Invalid parameter description in tool ${toolName}`, toolName, 'Parameter description must be a non-empty string');
|
|
45
|
+
}
|
|
46
|
+
if (typeof param.required !== 'boolean') {
|
|
47
|
+
throw new ToolRegistrationError(`Invalid parameter required flag in tool ${toolName}`, toolName, 'Parameter required must be a boolean');
|
|
48
|
+
}
|
|
49
|
+
if (param.enum !== undefined && !Array.isArray(param.enum)) {
|
|
50
|
+
throw new ToolRegistrationError(`Invalid parameter enum in tool ${toolName}`, toolName, 'Parameter enum must be an array of strings');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates a complete tool definition
|
|
55
|
+
*/
|
|
56
|
+
function validateTool(tool) {
|
|
57
|
+
// Validate name
|
|
58
|
+
if (!tool.name || typeof tool.name !== 'string') {
|
|
59
|
+
throw new ToolRegistrationError('Invalid tool name', tool.name || 'unknown', 'Tool name must be a non-empty string');
|
|
60
|
+
}
|
|
61
|
+
// Validate name format (alphanumeric, underscores, hyphens)
|
|
62
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(tool.name)) {
|
|
63
|
+
throw new ToolRegistrationError(`Invalid tool name format: ${tool.name}`, tool.name, 'Tool name must start with a letter and contain only alphanumeric characters, underscores, and hyphens');
|
|
64
|
+
}
|
|
65
|
+
// Validate description
|
|
66
|
+
if (!tool.description || typeof tool.description !== 'string') {
|
|
67
|
+
throw new ToolRegistrationError(`Invalid tool description for ${tool.name}`, tool.name, 'Tool description must be a non-empty string');
|
|
68
|
+
}
|
|
69
|
+
// Validate parameters
|
|
70
|
+
if (!Array.isArray(tool.parameters)) {
|
|
71
|
+
throw new ToolRegistrationError(`Invalid parameters for tool ${tool.name}`, tool.name, 'Tool parameters must be an array');
|
|
72
|
+
}
|
|
73
|
+
// Check for duplicate parameter names
|
|
74
|
+
const paramNames = new Set();
|
|
75
|
+
for (const param of tool.parameters) {
|
|
76
|
+
validateParameter(param, tool.name);
|
|
77
|
+
if (paramNames.has(param.name)) {
|
|
78
|
+
throw new ToolRegistrationError(`Duplicate parameter name "${param.name}" in tool ${tool.name}`, tool.name, 'Parameter names must be unique within a tool');
|
|
79
|
+
}
|
|
80
|
+
paramNames.add(param.name);
|
|
81
|
+
}
|
|
82
|
+
// Validate execute function
|
|
83
|
+
if (typeof tool.execute !== 'function') {
|
|
84
|
+
throw new ToolRegistrationError(`Invalid execute function for tool ${tool.name}`, tool.name, 'Tool execute must be a function');
|
|
85
|
+
}
|
|
86
|
+
// Validate optional fields
|
|
87
|
+
if (tool.riskLevel !== undefined) {
|
|
88
|
+
const validRiskLevels = ['low', 'medium', 'high'];
|
|
89
|
+
if (!validRiskLevels.includes(tool.riskLevel)) {
|
|
90
|
+
throw new ToolRegistrationError(`Invalid risk level for tool ${tool.name}`, tool.name, `Risk level must be one of: ${validRiskLevels.join(', ')}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Registry for managing Agent tools
|
|
96
|
+
*
|
|
97
|
+
* Provides methods to register, retrieve, and list tools.
|
|
98
|
+
* Ensures tool uniqueness and validates definitions.
|
|
99
|
+
*/
|
|
100
|
+
export class ToolRegistry {
|
|
101
|
+
tools = new Map();
|
|
102
|
+
options;
|
|
103
|
+
constructor(options = {}) {
|
|
104
|
+
this.options = {
|
|
105
|
+
allowReplace: options.allowReplace ?? false,
|
|
106
|
+
strictValidation: options.strictValidation ?? true,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Register a tool with the registry
|
|
111
|
+
*
|
|
112
|
+
* @param tool - The tool to register
|
|
113
|
+
* @throws ToolRegistrationError if validation fails or tool already exists
|
|
114
|
+
*/
|
|
115
|
+
register(tool) {
|
|
116
|
+
// Validate tool definition
|
|
117
|
+
if (this.options.strictValidation) {
|
|
118
|
+
validateTool(tool);
|
|
119
|
+
}
|
|
120
|
+
// Check for existing tool
|
|
121
|
+
if (this.tools.has(tool.name)) {
|
|
122
|
+
if (!this.options.allowReplace) {
|
|
123
|
+
throw new ToolRegistrationError(`Tool already registered: ${tool.name}`, tool.name, 'A tool with this name already exists. Use allowReplace option to override.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.tools.set(tool.name, tool);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Register multiple tools at once
|
|
130
|
+
*
|
|
131
|
+
* @param tools - Array of tools to register
|
|
132
|
+
* @throws ToolRegistrationError if any tool fails validation
|
|
133
|
+
*/
|
|
134
|
+
registerAll(tools) {
|
|
135
|
+
for (const tool of tools) {
|
|
136
|
+
this.register(tool);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get a tool by name
|
|
141
|
+
*
|
|
142
|
+
* @param name - The tool name
|
|
143
|
+
* @returns The tool if found, undefined otherwise
|
|
144
|
+
*/
|
|
145
|
+
get(name) {
|
|
146
|
+
return this.tools.get(name);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get a tool by name, throwing if not found
|
|
150
|
+
*
|
|
151
|
+
* @param name - The tool name
|
|
152
|
+
* @returns The tool
|
|
153
|
+
* @throws ToolNotFoundError if tool doesn't exist
|
|
154
|
+
*/
|
|
155
|
+
getOrThrow(name) {
|
|
156
|
+
const tool = this.tools.get(name);
|
|
157
|
+
if (!tool) {
|
|
158
|
+
throw new ToolNotFoundError(name);
|
|
159
|
+
}
|
|
160
|
+
return tool;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if a tool is registered
|
|
164
|
+
*
|
|
165
|
+
* @param name - The tool name
|
|
166
|
+
* @returns true if the tool exists
|
|
167
|
+
*/
|
|
168
|
+
has(name) {
|
|
169
|
+
return this.tools.has(name);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Remove a tool from the registry
|
|
173
|
+
*
|
|
174
|
+
* @param name - The tool name
|
|
175
|
+
* @returns true if the tool was removed, false if it didn't exist
|
|
176
|
+
*/
|
|
177
|
+
unregister(name) {
|
|
178
|
+
return this.tools.delete(name);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* List all registered tools
|
|
182
|
+
*
|
|
183
|
+
* @returns Array of all registered tools
|
|
184
|
+
*/
|
|
185
|
+
list() {
|
|
186
|
+
return Array.from(this.tools.values());
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* List tool names
|
|
190
|
+
*
|
|
191
|
+
* @returns Array of registered tool names
|
|
192
|
+
*/
|
|
193
|
+
listNames() {
|
|
194
|
+
return Array.from(this.tools.keys());
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* List tools by category
|
|
198
|
+
*
|
|
199
|
+
* @param category - The category to filter by
|
|
200
|
+
* @returns Array of tools in the specified category
|
|
201
|
+
*/
|
|
202
|
+
listByCategory(category) {
|
|
203
|
+
return this.list().filter((tool) => tool.category === category);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get all unique categories
|
|
207
|
+
*
|
|
208
|
+
* @returns Array of unique category names
|
|
209
|
+
*/
|
|
210
|
+
getCategories() {
|
|
211
|
+
const categories = new Set();
|
|
212
|
+
for (const tool of this.tools.values()) {
|
|
213
|
+
if (tool.category) {
|
|
214
|
+
categories.add(tool.category);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return Array.from(categories);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get tool definitions in Function Calling format
|
|
221
|
+
*
|
|
222
|
+
* @returns Array of tool definitions for LLM APIs
|
|
223
|
+
*/
|
|
224
|
+
getDefinitions() {
|
|
225
|
+
return this.list().map((tool) => toolToDefinition(tool));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get tool definitions for specific tools
|
|
229
|
+
*
|
|
230
|
+
* @param names - Array of tool names to get definitions for
|
|
231
|
+
* @returns Array of tool definitions
|
|
232
|
+
*/
|
|
233
|
+
getDefinitionsFor(names) {
|
|
234
|
+
return names
|
|
235
|
+
.map((name) => this.tools.get(name))
|
|
236
|
+
.filter((tool) => tool !== undefined)
|
|
237
|
+
.map((tool) => toolToDefinition(tool));
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get the number of registered tools
|
|
241
|
+
*/
|
|
242
|
+
get size() {
|
|
243
|
+
return this.tools.size;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Clear all registered tools
|
|
247
|
+
*/
|
|
248
|
+
clear() {
|
|
249
|
+
this.tools.clear();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=tool-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.js","sourceRoot":"","sources":["../../src/core/tool-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAG5B;IACA;IAHlB,YACE,OAAe,EAC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OAKG;IACH,iBAAiB,CAAC,KAAe;QAC/B,OAAO,KAAK;aACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACnC,MAAM,CAAC,CAAC,IAAI,EAAgB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC;aAClD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Agent Framework
|
|
3
|
+
*
|
|
4
|
+
* A modular AI Agent framework with LLM support, RAG knowledge retrieval,
|
|
5
|
+
* and extensible tool system.
|
|
6
|
+
*/
|
|
7
|
+
export * from './types/tool.js';
|
|
8
|
+
export * from './types/response.js';
|
|
9
|
+
export * from './types/config.js';
|
|
10
|
+
export * from './types/plugin.js';
|
|
11
|
+
export * from './types/streaming.js';
|
|
12
|
+
export type { LoopConfig, LoopStatus, LoopMessage, LLMToolCall, LoopState, LoopResult, LoopRunOptions, } from './types/loop.js';
|
|
13
|
+
export { DEFAULT_LOOP_CONFIG } from './types/loop.js';
|
|
14
|
+
export type { ToolCallRecord as LoopToolCallRecord } from './types/loop.js';
|
|
15
|
+
export type { Document, DocumentInput, SearchOptions, SearchResult, KnowledgeAssessment, } from './types/knowledge.js';
|
|
16
|
+
export * from './llm/index.js';
|
|
17
|
+
export { KnowledgeStore } from './knowledge/store.js';
|
|
18
|
+
export { Embedder } from './knowledge/embedder.js';
|
|
19
|
+
export { Retriever } from './knowledge/retriever.js';
|
|
20
|
+
export { MarkdownLoader } from './knowledge/loaders/markdown.js';
|
|
21
|
+
export { YamlLoader } from './knowledge/loaders/yaml.js';
|
|
22
|
+
export { TextChunker, createChunker, type ChunkerConfig, type TextChunk, } from './knowledge/chunker.js';
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use @ai-agent/storage-memory package instead.
|
|
25
|
+
* These exports are kept for backward compatibility.
|
|
26
|
+
*/
|
|
27
|
+
export { SessionManager } from './conversation/session.js';
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use @ai-agent/storage-memory package instead.
|
|
30
|
+
* These exports are kept for backward compatibility.
|
|
31
|
+
*/
|
|
32
|
+
export { MessageStore, type StoredMessage } from './conversation/message-store.js';
|
|
33
|
+
export { ContextBuilder, type ContextBuilderConfig } from './conversation/context-builder.js';
|
|
34
|
+
export { AuditLogger } from './audit/logger.js';
|
|
35
|
+
export { AuditLogQuery, type AuditLogQueryOptions } from './audit/query.js';
|
|
36
|
+
export { Agent } from './core/agent.js';
|
|
37
|
+
export { ToolRegistry } from './core/tool-registry.js';
|
|
38
|
+
export { ToolExecutor } from './core/tool-executor.js';
|
|
39
|
+
export { IntentParser, type Intent } from './core/intent-parser.js';
|
|
40
|
+
export { PlanGenerator, type ExecutionPlan } from './core/plan-generator.js';
|
|
41
|
+
export { ResponseHandler } from './core/response-handler.js';
|
|
42
|
+
export { PluginManager, PluginError } from './core/plugin-manager.js';
|
|
43
|
+
export { AgenticLoop, LoopError } from './core/agentic-loop.js';
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAErC,YAAY,EACV,UAAU,EACV,UA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B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Agent Framework
|
|
3
|
+
*
|
|
4
|
+
* A modular AI Agent framework with LLM support, RAG knowledge retrieval,
|
|
5
|
+
* and extensible tool system.
|
|
6
|
+
*/
|
|
7
|
+
// Types
|
|
8
|
+
export * from './types/tool.js';
|
|
9
|
+
export * from './types/response.js';
|
|
10
|
+
export * from './types/config.js';
|
|
11
|
+
export * from './types/plugin.js';
|
|
12
|
+
export * from './types/streaming.js';
|
|
13
|
+
export { DEFAULT_LOOP_CONFIG } from './types/loop.js';
|
|
14
|
+
// LLM Layer
|
|
15
|
+
export * from './llm/index.js';
|
|
16
|
+
// Knowledge System
|
|
17
|
+
export { KnowledgeStore } from './knowledge/store.js';
|
|
18
|
+
export { Embedder } from './knowledge/embedder.js';
|
|
19
|
+
export { Retriever } from './knowledge/retriever.js';
|
|
20
|
+
export { MarkdownLoader } from './knowledge/loaders/markdown.js';
|
|
21
|
+
export { YamlLoader } from './knowledge/loaders/yaml.js';
|
|
22
|
+
export { TextChunker, createChunker, } from './knowledge/chunker.js';
|
|
23
|
+
// Conversation System (Deprecated - use @ai-agent/storage-memory instead)
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use @ai-agent/storage-memory package instead.
|
|
26
|
+
* These exports are kept for backward compatibility.
|
|
27
|
+
*/
|
|
28
|
+
export { SessionManager } from './conversation/session.js';
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use @ai-agent/storage-memory package instead.
|
|
31
|
+
* These exports are kept for backward compatibility.
|
|
32
|
+
*/
|
|
33
|
+
export { MessageStore } from './conversation/message-store.js';
|
|
34
|
+
export { ContextBuilder } from './conversation/context-builder.js';
|
|
35
|
+
// Audit System
|
|
36
|
+
export { AuditLogger } from './audit/logger.js';
|
|
37
|
+
export { AuditLogQuery } from './audit/query.js';
|
|
38
|
+
// Core
|
|
39
|
+
export { Agent } from './core/agent.js';
|
|
40
|
+
export { ToolRegistry } from './core/tool-registry.js';
|
|
41
|
+
export { ToolExecutor } from './core/tool-executor.js';
|
|
42
|
+
export { IntentParser } from './core/intent-parser.js';
|
|
43
|
+
export { PlanGenerator } from './core/plan-generator.js';
|
|
44
|
+
export { ResponseHandler } from './core/response-handler.js';
|
|
45
|
+
export { PluginManager, PluginError } from './core/plugin-manager.js';
|
|
46
|
+
export { AgenticLoop, LoopError } from './core/agentic-loop.js';
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,QAAQ;AACR,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAWrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAWtD,YAAY;AACZ,cAAc,gBAAgB,CAAC;AAE/B,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,WAAW,EACX,aAAa,GAGd,MAAM,wBAAwB,CAAC;AAEhC,0EAA0E;AAC1E;;;GAGG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAsB,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,cAAc,EAA6B,MAAM,mCAAmC,CAAC;AAE9F,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAA6B,MAAM,kBAAkB,CAAC;AAE5E,OAAO;AACP,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAe,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAsB,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Chunker
|
|
3
|
+
*
|
|
4
|
+
* Handles intelligent text chunking for embedding generation.
|
|
5
|
+
* Splits large documents into smaller chunks while preserving context.
|
|
6
|
+
*
|
|
7
|
+
* _Requirements: 3.5_
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Chunk configuration options
|
|
11
|
+
*/
|
|
12
|
+
export interface ChunkerConfig {
|
|
13
|
+
/** Maximum characters per chunk (default: 2000) */
|
|
14
|
+
maxChunkSize?: number;
|
|
15
|
+
/** Overlap between chunks in characters (default: 200) */
|
|
16
|
+
chunkOverlap?: number;
|
|
17
|
+
/** Minimum chunk size to avoid tiny fragments (default: 100) */
|
|
18
|
+
minChunkSize?: number;
|
|
19
|
+
/** Separators to use for splitting, in order of priority */
|
|
20
|
+
separators?: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A chunk of text with metadata
|
|
24
|
+
*/
|
|
25
|
+
export interface TextChunk {
|
|
26
|
+
/** The chunk content */
|
|
27
|
+
content: string;
|
|
28
|
+
/** Index of this chunk in the original document */
|
|
29
|
+
index: number;
|
|
30
|
+
/** Start position in original text */
|
|
31
|
+
startPos: number;
|
|
32
|
+
/** End position in original text */
|
|
33
|
+
endPos: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Text Chunker class for splitting documents
|
|
37
|
+
*/
|
|
38
|
+
export declare class TextChunker {
|
|
39
|
+
private config;
|
|
40
|
+
constructor(config?: ChunkerConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Check if text needs chunking
|
|
43
|
+
*/
|
|
44
|
+
needsChunking(text: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Split text into chunks
|
|
47
|
+
*/
|
|
48
|
+
chunk(text: string): TextChunk[];
|
|
49
|
+
/**
|
|
50
|
+
* Recursively split text using separators
|
|
51
|
+
*/
|
|
52
|
+
private recursiveSplit;
|
|
53
|
+
/**
|
|
54
|
+
* Find the best separator that creates reasonable splits
|
|
55
|
+
*/
|
|
56
|
+
private findBestSeparator;
|
|
57
|
+
/**
|
|
58
|
+
* Split text by size when no good separator found
|
|
59
|
+
*/
|
|
60
|
+
private splitBySize;
|
|
61
|
+
/**
|
|
62
|
+
* Get overlap text from the end of a chunk
|
|
63
|
+
*/
|
|
64
|
+
private getOverlapText;
|
|
65
|
+
/**
|
|
66
|
+
* Get configuration
|
|
67
|
+
*/
|
|
68
|
+
getConfig(): Required<ChunkerConfig>;
|
|
69
|
+
/**
|
|
70
|
+
* Update configuration
|
|
71
|
+
*/
|
|
72
|
+
setConfig(config: Partial<ChunkerConfig>): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a default chunker instance
|
|
76
|
+
*/
|
|
77
|
+
export declare function createChunker(config?: ChunkerConfig): TextChunker;
|
|
78
|
+
//# sourceMappingURL=chunker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunker.d.ts","sourceRoot":"","sources":["../../src/knowledge/chunker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAyBD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,CAAC,EAAE,aAAa;IAIlC;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE;IAgBhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAgFtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,OAAO,CAAC,WAAW;IA+CnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAmBtB;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC;IAIpC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI;CAGhD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,WAAW,CAEjE"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Chunker
|
|
3
|
+
*
|
|
4
|
+
* Handles intelligent text chunking for embedding generation.
|
|
5
|
+
* Splits large documents into smaller chunks while preserving context.
|
|
6
|
+
*
|
|
7
|
+
* _Requirements: 3.5_
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
maxChunkSize: 500, // Reduced to ~250 tokens to fit BGE embedding model limits
|
|
11
|
+
chunkOverlap: 50, // Reduced proportionally
|
|
12
|
+
minChunkSize: 30, // Reduced proportionally
|
|
13
|
+
separators: [
|
|
14
|
+
'\n\n\n', // Triple newline (major sections)
|
|
15
|
+
'\n\n', // Double newline (paragraphs)
|
|
16
|
+
'\n', // Single newline
|
|
17
|
+
'。', // Chinese period
|
|
18
|
+
'.', // English period
|
|
19
|
+
'!', // Chinese exclamation
|
|
20
|
+
'!', // English exclamation
|
|
21
|
+
'?', // Chinese question mark
|
|
22
|
+
'?', // English question mark
|
|
23
|
+
';', // Chinese semicolon
|
|
24
|
+
';', // English semicolon
|
|
25
|
+
',', // Chinese comma
|
|
26
|
+
',', // English comma
|
|
27
|
+
' ', // Space
|
|
28
|
+
'', // Character by character (last resort)
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Text Chunker class for splitting documents
|
|
33
|
+
*/
|
|
34
|
+
export class TextChunker {
|
|
35
|
+
config;
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if text needs chunking
|
|
41
|
+
*/
|
|
42
|
+
needsChunking(text) {
|
|
43
|
+
return text.length > this.config.maxChunkSize;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Split text into chunks
|
|
47
|
+
*/
|
|
48
|
+
chunk(text) {
|
|
49
|
+
// If text is small enough, return as single chunk
|
|
50
|
+
if (!this.needsChunking(text)) {
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
content: text,
|
|
54
|
+
index: 0,
|
|
55
|
+
startPos: 0,
|
|
56
|
+
endPos: text.length,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
return this.recursiveSplit(text, this.config.separators);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Recursively split text using separators
|
|
64
|
+
*/
|
|
65
|
+
recursiveSplit(text, separators) {
|
|
66
|
+
const chunks = [];
|
|
67
|
+
if (text.length <= this.config.maxChunkSize) {
|
|
68
|
+
chunks.push({
|
|
69
|
+
content: text,
|
|
70
|
+
index: 0,
|
|
71
|
+
startPos: 0,
|
|
72
|
+
endPos: text.length,
|
|
73
|
+
});
|
|
74
|
+
return chunks;
|
|
75
|
+
}
|
|
76
|
+
// Find the best separator to use
|
|
77
|
+
const separator = this.findBestSeparator(text, separators);
|
|
78
|
+
if (separator === '') {
|
|
79
|
+
// Last resort: split by character count
|
|
80
|
+
return this.splitBySize(text);
|
|
81
|
+
}
|
|
82
|
+
// Split by separator
|
|
83
|
+
const splits = text.split(separator);
|
|
84
|
+
let currentChunk = '';
|
|
85
|
+
let currentStartPos = 0;
|
|
86
|
+
let position = 0;
|
|
87
|
+
for (let i = 0; i < splits.length; i++) {
|
|
88
|
+
const split = splits[i];
|
|
89
|
+
const splitWithSep = i < splits.length - 1 ? split + separator : split;
|
|
90
|
+
// Check if adding this split would exceed max size
|
|
91
|
+
if (currentChunk.length + splitWithSep.length > this.config.maxChunkSize) {
|
|
92
|
+
// Save current chunk if it's not empty
|
|
93
|
+
if (currentChunk.length >= this.config.minChunkSize) {
|
|
94
|
+
chunks.push({
|
|
95
|
+
content: currentChunk.trim(),
|
|
96
|
+
index: chunks.length,
|
|
97
|
+
startPos: currentStartPos,
|
|
98
|
+
endPos: position,
|
|
99
|
+
});
|
|
100
|
+
// Start new chunk with overlap
|
|
101
|
+
const overlapText = this.getOverlapText(currentChunk);
|
|
102
|
+
currentChunk = overlapText + splitWithSep;
|
|
103
|
+
currentStartPos = position - overlapText.length;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Current chunk too small, try to merge
|
|
107
|
+
currentChunk += splitWithSep;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
currentChunk += splitWithSep;
|
|
112
|
+
}
|
|
113
|
+
position += splitWithSep.length;
|
|
114
|
+
}
|
|
115
|
+
// Add remaining chunk
|
|
116
|
+
if (currentChunk.trim().length >= this.config.minChunkSize) {
|
|
117
|
+
chunks.push({
|
|
118
|
+
content: currentChunk.trim(),
|
|
119
|
+
index: chunks.length,
|
|
120
|
+
startPos: currentStartPos,
|
|
121
|
+
endPos: text.length,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else if (chunks.length > 0 && currentChunk.trim().length > 0) {
|
|
125
|
+
// Merge small remaining chunk with previous
|
|
126
|
+
const lastChunk = chunks[chunks.length - 1];
|
|
127
|
+
lastChunk.content = lastChunk.content + ' ' + currentChunk.trim();
|
|
128
|
+
lastChunk.endPos = text.length;
|
|
129
|
+
}
|
|
130
|
+
// Re-index chunks
|
|
131
|
+
chunks.forEach((chunk, idx) => {
|
|
132
|
+
chunk.index = idx;
|
|
133
|
+
});
|
|
134
|
+
return chunks;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Find the best separator that creates reasonable splits
|
|
138
|
+
*/
|
|
139
|
+
findBestSeparator(text, separators) {
|
|
140
|
+
for (const sep of separators) {
|
|
141
|
+
if (sep === '')
|
|
142
|
+
continue;
|
|
143
|
+
if (text.includes(sep)) {
|
|
144
|
+
const splits = text.split(sep);
|
|
145
|
+
// Check if this separator creates reasonable chunks
|
|
146
|
+
const avgSize = text.length / splits.length;
|
|
147
|
+
if (avgSize <= this.config.maxChunkSize * 1.5) {
|
|
148
|
+
return sep;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Return empty string to trigger character-based splitting
|
|
153
|
+
return '';
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Split text by size when no good separator found
|
|
157
|
+
*/
|
|
158
|
+
splitBySize(text) {
|
|
159
|
+
const chunks = [];
|
|
160
|
+
let position = 0;
|
|
161
|
+
while (position < text.length) {
|
|
162
|
+
let endPos = Math.min(position + this.config.maxChunkSize, text.length);
|
|
163
|
+
// Try to find a good break point (space or punctuation)
|
|
164
|
+
if (endPos < text.length) {
|
|
165
|
+
const searchStart = Math.max(position, endPos - 100);
|
|
166
|
+
let breakPoint = -1;
|
|
167
|
+
// Look for space or punctuation near the end
|
|
168
|
+
for (let i = endPos; i >= searchStart; i--) {
|
|
169
|
+
const char = text[i];
|
|
170
|
+
if (' \n\t。.!!??;;,,'.includes(char)) {
|
|
171
|
+
breakPoint = i + 1;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (breakPoint > position) {
|
|
176
|
+
endPos = breakPoint;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const chunkContent = text.slice(position, endPos).trim();
|
|
180
|
+
if (chunkContent.length >= this.config.minChunkSize) {
|
|
181
|
+
chunks.push({
|
|
182
|
+
content: chunkContent,
|
|
183
|
+
index: chunks.length,
|
|
184
|
+
startPos: position,
|
|
185
|
+
endPos: endPos,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
// Move position with overlap
|
|
189
|
+
position = endPos - this.config.chunkOverlap;
|
|
190
|
+
if (position <= chunks[chunks.length - 1]?.startPos) {
|
|
191
|
+
position = endPos; // Prevent infinite loop
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return chunks;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get overlap text from the end of a chunk
|
|
198
|
+
*/
|
|
199
|
+
getOverlapText(text) {
|
|
200
|
+
if (text.length <= this.config.chunkOverlap) {
|
|
201
|
+
return text;
|
|
202
|
+
}
|
|
203
|
+
const overlapStart = text.length - this.config.chunkOverlap;
|
|
204
|
+
// Try to start at a word boundary
|
|
205
|
+
let adjustedStart = overlapStart;
|
|
206
|
+
for (let i = overlapStart; i < Math.min(overlapStart + 50, text.length); i++) {
|
|
207
|
+
if (' \n\t'.includes(text[i])) {
|
|
208
|
+
adjustedStart = i + 1;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return text.slice(adjustedStart);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get configuration
|
|
216
|
+
*/
|
|
217
|
+
getConfig() {
|
|
218
|
+
return { ...this.config };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Update configuration
|
|
222
|
+
*/
|
|
223
|
+
setConfig(config) {
|
|
224
|
+
this.config = { ...this.config, ...config };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a default chunker instance
|
|
229
|
+
*/
|
|
230
|
+
export function createChunker(config) {
|
|
231
|
+
return new TextChunker(config);
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=chunker.js.map
|