@xpert-ai/plugin-sdk 3.6.0-beta.10 → 3.6.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.
Files changed (136) hide show
  1. package/.eslintrc.json +30 -0
  2. package/.swcrc +29 -0
  3. package/SCHEMA_SPECIFICATION.md +2 -0
  4. package/index.cjs.js +5 -649
  5. package/jest.config.ts +28 -0
  6. package/package.json +3 -3
  7. package/project.json +59 -0
  8. package/src/index.ts +11 -0
  9. package/src/lib/core/file-system.ts +113 -0
  10. package/src/lib/core/i18n.ts +31 -0
  11. package/src/lib/core/index.ts +4 -0
  12. package/src/lib/core/permissions.ts +97 -0
  13. package/src/lib/core/schema.ts +23 -0
  14. package/src/lib/integration/index.ts +3 -0
  15. package/src/lib/integration/strategy.decorator.ts +6 -0
  16. package/src/lib/integration/strategy.interface.ts +11 -0
  17. package/src/lib/integration/strategy.registry.ts +12 -0
  18. package/src/lib/logger.ts +18 -0
  19. package/src/lib/plugin-metadata.ts +20 -0
  20. package/src/lib/{plugin.hook.d.ts → plugin.hook.ts} +4 -0
  21. package/src/lib/plugin.interface.ts +67 -0
  22. package/src/lib/plugin.ts +32 -0
  23. package/src/lib/rag/image/index.ts +3 -0
  24. package/src/lib/rag/image/strategy.decorator.ts +9 -0
  25. package/src/lib/rag/image/strategy.interface.ts +37 -0
  26. package/src/lib/rag/image/strategy.registry.ts +17 -0
  27. package/src/lib/rag/index.ts +7 -0
  28. package/src/lib/rag/knowledge/index.ts +3 -0
  29. package/src/lib/rag/knowledge/knowledge-strategy.decorator.ts +6 -0
  30. package/src/lib/rag/knowledge/knowledge-strategy.interface.ts +15 -0
  31. package/src/lib/rag/knowledge/knowledge-strategy.registry.ts +12 -0
  32. package/src/lib/rag/retriever/index.ts +3 -0
  33. package/src/lib/rag/retriever/strategy.decorator.ts +9 -0
  34. package/src/lib/rag/retriever/strategy.interface.ts +32 -0
  35. package/src/lib/rag/retriever/strategy.registry.ts +12 -0
  36. package/src/lib/rag/source/index.ts +3 -0
  37. package/src/lib/rag/source/strategy.decorator.ts +9 -0
  38. package/src/lib/rag/source/strategy.interface.ts +36 -0
  39. package/src/lib/rag/source/strategy.registry.ts +17 -0
  40. package/src/lib/rag/textsplitter/index.ts +3 -0
  41. package/src/lib/rag/textsplitter/strategy.decorator.ts +6 -0
  42. package/src/lib/rag/textsplitter/strategy.interface.ts +28 -0
  43. package/src/lib/rag/textsplitter/strategy.registry.ts +17 -0
  44. package/src/lib/rag/transformer/index.ts +3 -0
  45. package/src/lib/rag/transformer/strategy.decorator.ts +9 -0
  46. package/src/lib/rag/transformer/strategy.interface.ts +34 -0
  47. package/src/lib/rag/transformer/strategy.registry.ts +14 -0
  48. package/src/lib/rag/types.ts +76 -0
  49. package/src/lib/strategy.ts +37 -0
  50. package/src/lib/toolset/builtin.ts +111 -0
  51. package/src/lib/toolset/index.ts +5 -0
  52. package/src/lib/toolset/strategy.decorator.ts +9 -0
  53. package/src/lib/toolset/strategy.interface.ts +32 -0
  54. package/src/lib/toolset/strategy.registry.ts +17 -0
  55. package/src/lib/toolset/toolset.ts +76 -0
  56. package/src/lib/types.ts +47 -0
  57. package/src/lib/vectorstore/index.ts +3 -0
  58. package/src/lib/vectorstore/strategy.decorator.ts +6 -0
  59. package/src/lib/vectorstore/strategy.interface.ts +25 -0
  60. package/src/lib/vectorstore/strategy.registry.ts +17 -0
  61. package/src/lib/workflow/index.ts +2 -0
  62. package/src/lib/workflow/node/index.ts +3 -0
  63. package/src/lib/workflow/node/strategy.decorator.ts +9 -0
  64. package/src/lib/workflow/node/strategy.interface.ts +51 -0
  65. package/src/lib/workflow/node/strategy.registry.ts +18 -0
  66. package/src/lib/workflow/trigger/index.ts +3 -0
  67. package/src/lib/workflow/trigger/strategy.decorator.ts +6 -0
  68. package/src/lib/workflow/trigger/strategy.interface.ts +27 -0
  69. package/src/lib/workflow/trigger/strategy.registry.ts +17 -0
  70. package/tsconfig.json +22 -0
  71. package/tsconfig.lib.json +10 -0
  72. package/tsconfig.spec.json +9 -0
  73. package/index.cjs.d.ts +0 -1
  74. package/index.esm.d.ts +0 -1
  75. package/index.esm.js +0 -616
  76. package/src/index.d.ts +0 -12
  77. package/src/lib/core/file-system.d.ts +0 -42
  78. package/src/lib/core/i18n.d.ts +0 -2
  79. package/src/lib/core/index.d.ts +0 -4
  80. package/src/lib/core/permissions.d.ts +0 -74
  81. package/src/lib/core/schema.d.ts +0 -22
  82. package/src/lib/integration/index.d.ts +0 -3
  83. package/src/lib/integration/strategy.decorator.d.ts +0 -2
  84. package/src/lib/integration/strategy.interface.d.ts +0 -9
  85. package/src/lib/integration/strategy.registry.d.ts +0 -6
  86. package/src/lib/knowledge/index.d.ts +0 -3
  87. package/src/lib/knowledge/knowledge-strategy.decorator.d.ts +0 -2
  88. package/src/lib/knowledge/knowledge-strategy.interface.d.ts +0 -15
  89. package/src/lib/knowledge/knowledge-strategy.registry.d.ts +0 -12
  90. package/src/lib/logger.d.ts +0 -2
  91. package/src/lib/plugin-metadata.d.ts +0 -17
  92. package/src/lib/plugin.d.ts +0 -8
  93. package/src/lib/plugin.interface.d.ts +0 -59
  94. package/src/lib/rag/image/index.d.ts +0 -3
  95. package/src/lib/rag/image/strategy.decorator.d.ts +0 -5
  96. package/src/lib/rag/image/strategy.interface.d.ts +0 -32
  97. package/src/lib/rag/image/strategy.registry.d.ts +0 -6
  98. package/src/lib/rag/index.d.ts +0 -6
  99. package/src/lib/rag/retriever/index.d.ts +0 -3
  100. package/src/lib/rag/retriever/strategy.decorator.d.ts +0 -5
  101. package/src/lib/rag/retriever/strategy.interface.d.ts +0 -30
  102. package/src/lib/rag/retriever/strategy.registry.d.ts +0 -6
  103. package/src/lib/rag/source/index.d.ts +0 -3
  104. package/src/lib/rag/source/strategy.decorator.d.ts +0 -5
  105. package/src/lib/rag/source/strategy.interface.d.ts +0 -36
  106. package/src/lib/rag/source/strategy.registry.d.ts +0 -6
  107. package/src/lib/rag/textsplitter/index.d.ts +0 -3
  108. package/src/lib/rag/textsplitter/strategy.decorator.d.ts +0 -2
  109. package/src/lib/rag/textsplitter/strategy.interface.d.ts +0 -24
  110. package/src/lib/rag/textsplitter/strategy.registry.d.ts +0 -6
  111. package/src/lib/rag/transformer/index.d.ts +0 -3
  112. package/src/lib/rag/transformer/strategy.decorator.d.ts +0 -5
  113. package/src/lib/rag/transformer/strategy.interface.d.ts +0 -26
  114. package/src/lib/rag/transformer/strategy.registry.d.ts +0 -6
  115. package/src/lib/rag/types.d.ts +0 -37
  116. package/src/lib/strategy.d.ts +0 -12
  117. package/src/lib/toolset/builtin.d.ts +0 -54
  118. package/src/lib/toolset/index.d.ts +0 -5
  119. package/src/lib/toolset/strategy.decorator.d.ts +0 -5
  120. package/src/lib/toolset/strategy.interface.d.ts +0 -28
  121. package/src/lib/toolset/strategy.registry.d.ts +0 -6
  122. package/src/lib/toolset/toolset.d.ts +0 -53
  123. package/src/lib/types.d.ts +0 -47
  124. package/src/lib/vectorstore/index.d.ts +0 -3
  125. package/src/lib/vectorstore/strategy.decorator.d.ts +0 -2
  126. package/src/lib/vectorstore/strategy.interface.d.ts +0 -24
  127. package/src/lib/vectorstore/strategy.registry.d.ts +0 -6
  128. package/src/lib/workflow/index.d.ts +0 -2
  129. package/src/lib/workflow/node/index.d.ts +0 -3
  130. package/src/lib/workflow/node/strategy.decorator.d.ts +0 -5
  131. package/src/lib/workflow/node/strategy.interface.d.ts +0 -40
  132. package/src/lib/workflow/node/strategy.registry.d.ts +0 -9
  133. package/src/lib/workflow/trigger/index.d.ts +0 -3
  134. package/src/lib/workflow/trigger/strategy.decorator.d.ts +0 -2
  135. package/src/lib/workflow/trigger/strategy.interface.d.ts +0 -22
  136. package/src/lib/workflow/trigger/strategy.registry.d.ts +0 -6
package/index.esm.js DELETED
@@ -1,616 +0,0 @@
1
- import { Module, Logger, SetMetadata, Injectable } from '@nestjs/common';
2
- import { MODULE_METADATA } from '@nestjs/common/constants';
3
- import { pick } from 'lodash-es';
4
- import { DiscoveryService, Reflector } from '@nestjs/core';
5
- import fs from 'fs';
6
- import http from 'http';
7
- import https from 'https';
8
- import { BaseToolkit, StructuredTool } from '@langchain/core/tools';
9
- import { z } from 'zod';
10
- import fsPromises from 'fs/promises';
11
- import path from 'path';
12
- import { createInstance } from 'i18next';
13
- import FsBackend from 'i18next-fs-backend';
14
-
15
- /**
16
- * Metadata keys used in plugins for defining various aspects like entities, subscribers, and configurations.
17
- */ const PLUGIN_METADATA = {
18
- /**
19
- * Key representing the entities registered within the plugin.
20
- */ ENTITIES: 'entities',
21
- /**
22
- * Key representing event subscribers within the plugin.
23
- */ SUBSCRIBERS: 'subscribers'
24
- };
25
-
26
- /**
27
- * Decorator function for extending NestJS features with additional metadata.
28
- *
29
- * @param pluginMetadata Metadata to be applied to the target class.
30
- * @returns Class decorator function.
31
- */ function XpertServerPlugin(pluginMetadata) {
32
- return (targetClass)=>{
33
- // Iterate over properties in PLUGIN_METADATA
34
- for (const metadataProperty of Object.values(PLUGIN_METADATA)){
35
- const property = metadataProperty;
36
- // Check if the property exists in pluginMetadata and is not undefined
37
- if (property in pluginMetadata && pluginMetadata[property] !== undefined) {
38
- // Set metadata on the target class using Reflect
39
- Reflect.defineMetadata(property, pluginMetadata[property] || [], targetClass);
40
- }
41
- }
42
- // Pick relevant metadata from pluginMetadata based on MODULE_METADATA values
43
- const metadata = pick(pluginMetadata, Object.values(MODULE_METADATA));
44
- // Apply the Module decorator with the picked metadata
45
- Module(metadata)(targetClass);
46
- };
47
- }
48
-
49
- function _extends() {
50
- _extends = Object.assign || function assign(target) {
51
- for(var i = 1; i < arguments.length; i++){
52
- var source = arguments[i];
53
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
54
- }
55
- return target;
56
- };
57
- return _extends.apply(this, arguments);
58
- }
59
-
60
- function createPluginLogger(scope, baseMeta = {}) {
61
- const nestLogger = new Logger(scope);
62
- const wrap = (level, msg, meta)=>{
63
- var _nestLogger_level;
64
- const payload = meta ? _extends({}, baseMeta, meta) : baseMeta;
65
- (_nestLogger_level = // 保持与 Nest Logger 接口对齐
66
- nestLogger[level]) == null ? void 0 : _nestLogger_level.call(nestLogger, msg + (Object.keys(payload).length ? ` ${JSON.stringify(payload)}` : ''));
67
- };
68
- return {
69
- child (meta) {
70
- return createPluginLogger(scope, _extends({}, baseMeta, meta));
71
- },
72
- debug: (msg, meta)=>wrap('debug', msg, meta),
73
- log: (msg, meta)=>wrap('log', msg, meta),
74
- warn: (msg, meta)=>wrap('warn', msg, meta),
75
- error: (msg, meta)=>wrap('error', msg, meta)
76
- };
77
- }
78
-
79
- const KNOWLEDGE_STRATEGY = 'KNOWLEDGE_STRATEGY';
80
- const KnowledgeStrategyKey = (provider)=>SetMetadata(KNOWLEDGE_STRATEGY, provider);
81
-
82
- function __decorate(decorators, target, key, desc) {
83
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
85
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
86
- return c > 3 && r && Object.defineProperty(target, key, r), r;
87
- }
88
- function __metadata(metadataKey, metadataValue) {
89
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
90
- }
91
- typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
92
- var e = new Error(message);
93
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
94
- };
95
-
96
- let KnowledgeStrategyRegistry = class KnowledgeStrategyRegistry {
97
- onModuleInit() {
98
- const providers = this.discoveryService.getProviders();
99
- for (const wrapper of providers){
100
- const { instance } = wrapper;
101
- if (!instance) continue;
102
- const type = this.reflector.get(KNOWLEDGE_STRATEGY, instance.constructor);
103
- if (type) {
104
- this.strategies.set(type, instance);
105
- }
106
- }
107
- }
108
- get(type) {
109
- const strategy = this.strategies.get(type);
110
- if (!strategy) {
111
- throw new Error(`No strategy found for type ${type}`);
112
- }
113
- return strategy;
114
- }
115
- constructor(discoveryService, reflector){
116
- this.discoveryService = discoveryService;
117
- this.reflector = reflector;
118
- this.strategies = new Map();
119
- }
120
- };
121
- KnowledgeStrategyRegistry = __decorate([
122
- Injectable(),
123
- __metadata("design:type", Function),
124
- __metadata("design:paramtypes", [
125
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
126
- typeof Reflector === "undefined" ? Object : Reflector
127
- ])
128
- ], KnowledgeStrategyRegistry);
129
-
130
- const INTEGRATION_STRATEGY = 'INTEGRATION_STRATEGY';
131
- const IntegrationStrategyKey = (provider)=>SetMetadata(INTEGRATION_STRATEGY, provider);
132
-
133
- class BaseStrategyRegistry {
134
- onModuleInit() {
135
- const providers = this.discoveryService.getProviders();
136
- for (const wrapper of providers){
137
- const { instance } = wrapper;
138
- if (!instance) continue;
139
- const type = this.reflector.get(this.strategyKey, instance.constructor);
140
- if (type) {
141
- this.strategies.set(type, instance);
142
- }
143
- }
144
- }
145
- get(type) {
146
- const strategy = this.strategies.get(type);
147
- if (!strategy) {
148
- throw new Error(`No strategy found for type ${type}`);
149
- }
150
- return strategy;
151
- }
152
- list() {
153
- return Array.from(this.strategies.values());
154
- }
155
- constructor(strategyKey, discoveryService, reflector){
156
- this.strategyKey = strategyKey;
157
- this.discoveryService = discoveryService;
158
- this.reflector = reflector;
159
- this.strategies = new Map();
160
- }
161
- }
162
-
163
- let IntegrationStrategyRegistry = class IntegrationStrategyRegistry extends BaseStrategyRegistry {
164
- constructor(discoveryService, reflector){
165
- super(INTEGRATION_STRATEGY, discoveryService, reflector);
166
- }
167
- };
168
- IntegrationStrategyRegistry = __decorate([
169
- Injectable(),
170
- __metadata("design:type", Function),
171
- __metadata("design:paramtypes", [
172
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
173
- typeof Reflector === "undefined" ? Object : Reflector
174
- ])
175
- ], IntegrationStrategyRegistry);
176
-
177
- const WORKFLOW_TRIGGER_STRATEGY = 'WORKFLOW_TRIGGER_STRATEGY';
178
- const WorkflowTriggerStrategy = (provider)=>SetMetadata(WORKFLOW_TRIGGER_STRATEGY, provider);
179
-
180
- let WorkflowTriggerRegistry = class WorkflowTriggerRegistry extends BaseStrategyRegistry {
181
- constructor(discoveryService, reflector){
182
- super(WORKFLOW_TRIGGER_STRATEGY, discoveryService, reflector);
183
- }
184
- };
185
- WorkflowTriggerRegistry = __decorate([
186
- Injectable(),
187
- __metadata("design:type", Function),
188
- __metadata("design:paramtypes", [
189
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
190
- typeof Reflector === "undefined" ? Object : Reflector
191
- ])
192
- ], WorkflowTriggerRegistry);
193
-
194
- const WORKFLOW_NODE_STRATEGY = 'WORKFLOW_NODE_STRATEGY';
195
- /**
196
- * Decorator to mark a provider as a Workflow Node Strategy
197
- */ const WorkflowNodeStrategy = (provider)=>SetMetadata(WORKFLOW_NODE_STRATEGY, provider);
198
-
199
- let WorkflowNodeRegistry = class WorkflowNodeRegistry extends BaseStrategyRegistry {
200
- constructor(discoveryService, reflector){
201
- super(WORKFLOW_NODE_STRATEGY, discoveryService, reflector);
202
- }
203
- };
204
- WorkflowNodeRegistry = __decorate([
205
- Injectable(),
206
- __metadata("design:type", Function),
207
- __metadata("design:paramtypes", [
208
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
209
- typeof Reflector === "undefined" ? Object : Reflector
210
- ])
211
- ], WorkflowNodeRegistry);
212
-
213
- const VECTOR_STORE_STRATEGY = 'VECTOR_STORE_STRATEGY';
214
- const VectorStoreStrategy = (provider)=>SetMetadata(VECTOR_STORE_STRATEGY, provider);
215
-
216
- let VectorStoreRegistry = class VectorStoreRegistry extends BaseStrategyRegistry {
217
- constructor(discoveryService, reflector){
218
- super(VECTOR_STORE_STRATEGY, discoveryService, reflector);
219
- }
220
- };
221
- VectorStoreRegistry = __decorate([
222
- Injectable(),
223
- __metadata("design:type", Function),
224
- __metadata("design:paramtypes", [
225
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
226
- typeof Reflector === "undefined" ? Object : Reflector
227
- ])
228
- ], VectorStoreRegistry);
229
-
230
- const TEXT_SPLITTER_STRATEGY = 'TEXT_SPLITTER_STRATEGY';
231
- const TextSplitterStrategy = (provider)=>SetMetadata(TEXT_SPLITTER_STRATEGY, provider);
232
-
233
- let TextSplitterRegistry = class TextSplitterRegistry extends BaseStrategyRegistry {
234
- constructor(discoveryService, reflector){
235
- super(TEXT_SPLITTER_STRATEGY, discoveryService, reflector);
236
- }
237
- };
238
- TextSplitterRegistry = __decorate([
239
- Injectable(),
240
- __metadata("design:type", Function),
241
- __metadata("design:paramtypes", [
242
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
243
- typeof Reflector === "undefined" ? Object : Reflector
244
- ])
245
- ], TextSplitterRegistry);
246
-
247
- const DOCUMENT_SOURCE_STRATEGY = 'DOCUMENT_SOURCE_STRATEGY';
248
- /**
249
- * Decorator to mark a provider as a Document Source Strategy
250
- */ const DocumentSourceStrategy = (provider)=>SetMetadata(DOCUMENT_SOURCE_STRATEGY, provider);
251
-
252
- let DocumentSourceRegistry = class DocumentSourceRegistry extends BaseStrategyRegistry {
253
- constructor(discoveryService, reflector){
254
- super(DOCUMENT_SOURCE_STRATEGY, discoveryService, reflector);
255
- }
256
- };
257
- DocumentSourceRegistry = __decorate([
258
- Injectable(),
259
- __metadata("design:type", Function),
260
- __metadata("design:paramtypes", [
261
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
262
- typeof Reflector === "undefined" ? Object : Reflector
263
- ])
264
- ], DocumentSourceRegistry);
265
-
266
- const DOCUMENT_TRANSFORMER_STRATEGY = 'DOCUMENT_TRANSFORMER_STRATEGY';
267
- /**
268
- * Decorator to mark a provider as a Document Transformer Strategy
269
- */ const DocumentTransformerStrategy = (provider)=>SetMetadata(DOCUMENT_TRANSFORMER_STRATEGY, provider);
270
-
271
- let DocumentTransformerRegistry = class DocumentTransformerRegistry extends BaseStrategyRegistry {
272
- constructor(discoveryService, reflector){
273
- super(DOCUMENT_TRANSFORMER_STRATEGY, discoveryService, reflector);
274
- }
275
- };
276
- DocumentTransformerRegistry = __decorate([
277
- Injectable(),
278
- __metadata("design:type", Function),
279
- __metadata("design:paramtypes", [
280
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
281
- typeof Reflector === "undefined" ? Object : Reflector
282
- ])
283
- ], DocumentTransformerRegistry);
284
-
285
- const RETRIEVER_STRATEGY = 'RETRIEVER_STRATEGY';
286
- /**
287
- * Decorator to mark a provider as a Retriever Strategy
288
- */ const RetrieverStrategy = (provider)=>SetMetadata(RETRIEVER_STRATEGY, provider);
289
-
290
- let RetrieverRegistry = class RetrieverRegistry extends BaseStrategyRegistry {
291
- constructor(discoveryService, reflector){
292
- super(RETRIEVER_STRATEGY, discoveryService, reflector);
293
- }
294
- };
295
- RetrieverRegistry = __decorate([
296
- Injectable(),
297
- __metadata("design:type", Function),
298
- __metadata("design:paramtypes", [
299
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
300
- typeof Reflector === "undefined" ? Object : Reflector
301
- ])
302
- ], RetrieverRegistry);
303
-
304
- /**
305
- * Merge parent chunks with their child chunks based on metadata (parentId and chunkId)
306
- * @param chunks
307
- * @param children
308
- * @returns
309
- */ function mergeParentChildChunks(chunks, children // Child chunks
310
- ) {
311
- const chunkMap = new Map();
312
- for (const chunk of chunks){
313
- chunkMap.set(chunk.metadata.chunkId, chunk);
314
- }
315
- for (const child of children){
316
- if (!child.metadata.parentId) {
317
- if (chunkMap.has(child.metadata.chunkId)) {
318
- console.warn(`Duplicate chunkId found: ${child.metadata.chunkId}, skipping...`);
319
- continue;
320
- }
321
- chunkMap.set(child.metadata.chunkId, child);
322
- continue;
323
- }
324
- const parent = chunkMap.get(child.metadata.parentId);
325
- if (parent) {
326
- if (!parent.metadata.children) {
327
- parent.metadata.children = [];
328
- }
329
- parent.metadata.children.push(child);
330
- }
331
- }
332
- return Array.from(chunkMap.values());
333
- }
334
- function isRemoteFile(path) {
335
- return path.startsWith('http://') || path.startsWith('https://') || path.startsWith('ftp://');
336
- }
337
- async function downloadRemoteFile(url, dest) {
338
- return new Promise((resolve, reject)=>{
339
- const file = fs.createWriteStream(dest);
340
- const client = url.startsWith('https') ? https : http;
341
- const request = client.get(url, (response)=>{
342
- if (response.statusCode !== 200) {
343
- reject(new Error(`Failed to get '${url}' (${response.statusCode})`));
344
- return;
345
- }
346
- response.pipe(file);
347
- });
348
- file.on('finish', ()=>{
349
- file.close();
350
- resolve(dest);
351
- });
352
- request.on('error', (err)=>{
353
- fs.unlink(dest, ()=>reject(err));
354
- });
355
- file.on('error', (err)=>{
356
- fs.unlink(dest, ()=>reject(err));
357
- });
358
- });
359
- }
360
-
361
- const IMAGE_UNDERSTANDING_STRATEGY = 'IMAGE_UNDERSTANDING_STRATEGY';
362
- /**
363
- * Decorator to mark a provider as an Image Understanding Strategy
364
- */ const ImageUnderstandingStrategy = (provider)=>SetMetadata(IMAGE_UNDERSTANDING_STRATEGY, provider);
365
-
366
- let ImageUnderstandingRegistry = class ImageUnderstandingRegistry extends BaseStrategyRegistry {
367
- constructor(discoveryService, reflector){
368
- super(IMAGE_UNDERSTANDING_STRATEGY, discoveryService, reflector);
369
- }
370
- };
371
- ImageUnderstandingRegistry = __decorate([
372
- Injectable(),
373
- __metadata("design:type", Function),
374
- __metadata("design:paramtypes", [
375
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
376
- typeof Reflector === "undefined" ? Object : Reflector
377
- ])
378
- ], ImageUnderstandingRegistry);
379
-
380
- const TOOLSET_STRATEGY = 'TOOLSET_STRATEGY';
381
- /**
382
- * Decorator to mark a provider as a Toolset Strategy
383
- */ const ToolsetStrategy = (provider)=>SetMetadata(TOOLSET_STRATEGY, provider);
384
-
385
- let ToolsetRegistry = class ToolsetRegistry extends BaseStrategyRegistry {
386
- constructor(discoveryService, reflector){
387
- super(TOOLSET_STRATEGY, discoveryService, reflector);
388
- }
389
- };
390
- ToolsetRegistry = __decorate([
391
- Injectable(),
392
- __metadata("design:type", Function),
393
- __metadata("design:paramtypes", [
394
- typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
395
- typeof Reflector === "undefined" ? Object : Reflector
396
- ])
397
- ], ToolsetRegistry);
398
-
399
- /**
400
- * Base ability for all toolsets
401
- */ class BaseToolset extends BaseToolkit {
402
- /**
403
- * Async init tools
404
- *
405
- * @returns
406
- */ async initTools() {
407
- return this.tools;
408
- }
409
- /**
410
- * Get one tool
411
- *
412
- * @param toolName
413
- * @returns
414
- */ getTool(toolName) {
415
- var _this_getTools;
416
- return (_this_getTools = this.getTools()) == null ? void 0 : _this_getTools.find((tool)=>tool.name === toolName);
417
- }
418
- /**
419
- * Get state variables config
420
- *
421
- * @returns State variables
422
- */ async getVariables() {
423
- return null;
424
- }
425
- /**
426
- * Close all (connections).
427
- */ async close() {
428
- //
429
- }
430
- constructor(params){
431
- super();
432
- this.params = params;
433
- }
434
- }
435
- class BaseTool extends StructuredTool {
436
- constructor(...args){
437
- super(...args);
438
- this.schema = z.object({
439
- input: z.string().optional()
440
- }).transform((obj)=>obj.input);
441
- }
442
- }
443
-
444
- class BuiltinToolset extends BaseToolset {
445
- get tenantId() {
446
- var _this_params;
447
- return (_this_params = this.params) == null ? void 0 : _this_params.tenantId;
448
- }
449
- get organizationId() {
450
- var _this_params;
451
- return (_this_params = this.params) == null ? void 0 : _this_params.organizationId;
452
- }
453
- get commandBus() {
454
- var _this_params;
455
- return (_this_params = this.params) == null ? void 0 : _this_params.commandBus;
456
- }
457
- get queryBus() {
458
- var _this_params;
459
- return (_this_params = this.params) == null ? void 0 : _this_params.queryBus;
460
- }
461
- get xpertId() {
462
- var _this_params;
463
- return (_this_params = this.params) == null ? void 0 : _this_params.xpertId;
464
- }
465
- async validateCredentials(credentials) {
466
- await this._validateCredentials(credentials);
467
- }
468
- async _validateCredentials(credentials) {
469
- throw new Error('Method not implemented.');
470
- }
471
- getId() {
472
- var _this_toolset;
473
- return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.id;
474
- }
475
- getCredentials() {
476
- var _this_toolset;
477
- return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.credentials;
478
- }
479
- getToolTitle(name) {
480
- var _this_toolset_tools, _this_toolset, _this;
481
- const tool = (_this_toolset = this.toolset) == null ? void 0 : (_this_toolset_tools = _this_toolset.tools) == null ? void 0 : _this_toolset_tools.find((tool)=>tool.name === name);
482
- const identity = (_this = tool == null ? void 0 : tool.schema) == null ? void 0 : _this.identity;
483
- if (identity) {
484
- return identity.label;
485
- }
486
- return null;
487
- }
488
- /**
489
- * Get credentials schema
490
- *
491
- * @returns Credentials schema
492
- */ getCredentialsSchema() {
493
- return _extends({}, this.credentialsSchema);
494
- }
495
- /**
496
- * Get toolset entity
497
- *
498
- * @returns XpertToolset
499
- */ getToolset() {
500
- return this.toolset;
501
- }
502
- getName() {
503
- var _this_getToolset;
504
- return (_this_getToolset = this.getToolset()) == null ? void 0 : _this_getToolset.name;
505
- }
506
- constructor(providerName, toolset, params){
507
- super(params);
508
- this.providerName = providerName;
509
- this.toolset = toolset;
510
- this.params = params;
511
- this.logger = new Logger(this.constructor.name);
512
- }
513
- }
514
- BuiltinToolset.provider = '';
515
-
516
- /**
517
- * Restricted FileSystem based on granted permissions
518
- */ class XpFileSystem {
519
- /**
520
- * Check if operation is allowed
521
- */ ensureAllowed(op) {
522
- if (!this.allowedOps.has(op)) {
523
- throw new Error(`Permission denied: ${op} operation not allowed`);
524
- }
525
- }
526
- /**
527
- * Check if path is within scope
528
- */ ensureInScope(targetPath) {
529
- if (!this.scope || this.scope.length === 0) return;
530
- const resolved = path.resolve(targetPath);
531
- for (const s of this.scope){
532
- const absScope = path.resolve(s);
533
- if (resolved.startsWith(absScope)) return;
534
- }
535
- throw new Error(`Permission denied: path "${targetPath}" is out of scope`);
536
- }
537
- fullPath(filePath) {
538
- return path.join(this.basePath, filePath);
539
- }
540
- /**
541
- * Read file contents
542
- */ async readFile(filePath, encoding = 'utf-8') {
543
- this.ensureAllowed('read');
544
- const fullPath = this.fullPath(filePath);
545
- this.ensureInScope(fullPath);
546
- return await fsPromises.readFile(fullPath);
547
- }
548
- /**
549
- * Write file contents
550
- */ async writeFile(filePath, content) {
551
- this.ensureAllowed('write');
552
- const fullPath = this.fullPath(filePath);
553
- this.ensureInScope(fullPath);
554
- await fsPromises.mkdir(path.dirname(fullPath), {
555
- recursive: true
556
- });
557
- await fsPromises.writeFile(fullPath, content);
558
- const url = new URL(filePath, this.baseUrl);
559
- return url.href;
560
- }
561
- /**
562
- * Delete a file
563
- */ async deleteFile(filePath) {
564
- this.ensureAllowed('delete');
565
- this.ensureInScope(filePath);
566
- await fsPromises.unlink(filePath);
567
- }
568
- /**
569
- * List directory contents
570
- */ async listDir(dirPath) {
571
- this.ensureAllowed('list');
572
- this.ensureInScope(dirPath);
573
- return fsPromises.readdir(dirPath);
574
- }
575
- /**
576
- * Utility: check if a file or directory exists
577
- */ async exists(targetPath) {
578
- try {
579
- await fsPromises.access(targetPath);
580
- return true;
581
- } catch (e) {
582
- return false;
583
- }
584
- }
585
- constructor(permission, basePath, baseUrl){
586
- this.basePath = basePath;
587
- this.baseUrl = baseUrl;
588
- this.allowedOps = new Set(permission.operations);
589
- this.scope = permission.scope;
590
- }
591
- }
592
-
593
- async function createI18nInstance(pluginDir, language) {
594
- const instance = createInstance();
595
- const i18nDir = path.join(pluginDir, 'i18n');
596
- // detect available languages dynamically
597
- const lngs = fs.readdirSync(i18nDir).filter((f)=>f.endsWith('.json')).map((f)=>f.replace('.json', ''));
598
- await instance.use(FsBackend).init({
599
- lng: language,
600
- fallbackLng: 'en',
601
- preload: lngs,
602
- ns: [
603
- 'default'
604
- ],
605
- defaultNS: 'default',
606
- backend: {
607
- loadPath: path.join(i18nDir, '{{lng}}.json')
608
- },
609
- interpolation: {
610
- escapeValue: false
611
- }
612
- });
613
- return instance;
614
- }
615
-
616
- export { BaseTool, BaseToolset, BuiltinToolset, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, IMAGE_UNDERSTANDING_STRATEGY, INTEGRATION_STRATEGY, ImageUnderstandingRegistry, ImageUnderstandingStrategy, IntegrationStrategyKey, IntegrationStrategyRegistry, KNOWLEDGE_STRATEGY, KnowledgeStrategyKey, KnowledgeStrategyRegistry, PLUGIN_METADATA, RETRIEVER_STRATEGY, RetrieverRegistry, RetrieverStrategy, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextSplitterRegistry, TextSplitterStrategy, ToolsetRegistry, ToolsetStrategy, VECTOR_STORE_STRATEGY, VectorStoreRegistry, VectorStoreStrategy, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, XpFileSystem, XpertServerPlugin, createI18nInstance, createPluginLogger, downloadRemoteFile, isRemoteFile, mergeParentChildChunks };
package/src/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from './lib/plugin';
2
- export * from './lib/plugin.interface';
3
- export * from './lib/plugin-metadata';
4
- export * from './lib/types';
5
- export * from './lib/logger';
6
- export * from './lib/knowledge';
7
- export * from './lib/integration/index';
8
- export * from './lib/workflow/index';
9
- export * from './lib/vectorstore/index';
10
- export * from './lib/rag/index';
11
- export * from './lib/toolset/index';
12
- export * from './lib/core/index';
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { FileSystemPermission } from './permissions';
4
- /**
5
- * Restricted FileSystem based on granted permissions
6
- */
7
- export declare class XpFileSystem {
8
- private basePath;
9
- private baseUrl;
10
- private allowedOps;
11
- private scope;
12
- constructor(permission: FileSystemPermission, basePath: string, baseUrl: string);
13
- /**
14
- * Check if operation is allowed
15
- */
16
- private ensureAllowed;
17
- /**
18
- * Check if path is within scope
19
- */
20
- private ensureInScope;
21
- fullPath(filePath: string): string;
22
- /**
23
- * Read file contents
24
- */
25
- readFile(filePath: string, encoding?: BufferEncoding): Promise<Buffer>;
26
- /**
27
- * Write file contents
28
- */
29
- writeFile(filePath: string, content: string | Buffer): Promise<string>;
30
- /**
31
- * Delete a file
32
- */
33
- deleteFile(filePath: string): Promise<void>;
34
- /**
35
- * List directory contents
36
- */
37
- listDir(dirPath: string): Promise<string[]>;
38
- /**
39
- * Utility: check if a file or directory exists
40
- */
41
- exists(targetPath: string): Promise<boolean>;
42
- }
@@ -1,2 +0,0 @@
1
- import { i18n as I18nInstance } from 'i18next';
2
- export declare function createI18nInstance(pluginDir: string, language?: string): Promise<I18nInstance>;
@@ -1,4 +0,0 @@
1
- export * from './file-system';
2
- export * from './permissions';
3
- export * from './schema';
4
- export * from './i18n';