@xpert-ai/plugin-sdk 3.8.3 → 3.9.0-beta.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/index.cjs.js +543 -325
- package/index.esm.js +526 -298
- package/package.json +4 -3
- package/src/index.d.ts +1 -0
- package/src/lib/agent/handoff/handoff-processor.decorator.d.ts +1 -1
- package/src/lib/agent/index.d.ts +1 -0
- package/src/lib/agent/middleware/strategy.decorator.d.ts +1 -1
- package/src/lib/agent/skill/skill-source-provider.decorator.d.ts +1 -1
- package/src/lib/agent/skill/skill-source-provider.interface.d.ts +1 -1
- package/src/lib/ai-model/llm.d.ts +9 -0
- package/src/lib/channel/strategy.interface.d.ts +0 -2
- package/src/lib/core/context/request-context.d.ts +7 -4
- package/src/lib/core/context/request-context.middleware.d.ts +0 -1
- package/src/lib/core/file-system.d.ts +1 -3
- package/src/lib/core/permissions/analytics.d.ts +2 -3
- package/src/lib/core/permissions/general.d.ts +2 -1
- package/src/lib/data/datasource/strategy.decorator.d.ts +1 -1
- package/src/lib/data/datasource/types.d.ts +0 -3
- package/src/lib/file/file-storage/provider.decorator.d.ts +1 -1
- package/src/lib/file/file-storage/provider.interface.d.ts +0 -2
- package/src/lib/file/file-upload/strategy.decorator.d.ts +1 -1
- package/src/lib/file/file-upload/strategy.interface.d.ts +0 -2
- package/src/lib/integration/strategy.decorator.d.ts +1 -1
- package/src/lib/integration/strategy.interface.d.ts +15 -3
- package/src/lib/rag/image/strategy.decorator.d.ts +1 -1
- package/src/lib/rag/knowledge/knowledge-strategy.decorator.d.ts +1 -1
- package/src/lib/rag/retriever/strategy.decorator.d.ts +1 -1
- package/src/lib/rag/source/strategy.decorator.d.ts +1 -1
- package/src/lib/rag/textsplitter/strategy.decorator.d.ts +1 -1
- package/src/lib/rag/transformer/strategy.decorator.d.ts +1 -1
- package/src/lib/sandbox/protocol.d.ts +6 -8
- package/src/lib/sandbox/sandbox.d.ts +6 -0
- package/src/lib/sandbox/sandbox.decorator.d.ts +1 -1
- package/src/lib/sandbox/sandbox.interface.d.ts +7 -11
- package/src/lib/strategy.d.ts +3 -3
- package/src/lib/toolset/strategy.decorator.d.ts +1 -1
- package/src/lib/vectorstore/strategy.decorator.d.ts +1 -1
- package/src/lib/view-extension/index.d.ts +3 -0
- package/src/lib/view-extension/provider.decorator.d.ts +2 -0
- package/src/lib/view-extension/provider.interface.d.ts +7 -0
- package/src/lib/view-extension/provider.registry.d.ts +10 -0
- package/src/lib/workflow/node/strategy.decorator.d.ts +1 -1
- package/src/lib/workflow/trigger/strategy.decorator.d.ts +1 -1
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
package/index.esm.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Module, Logger, applyDecorators, SetMetadata, HttpException, HttpStatus, Injectable, Inject, NotFoundException, ForbiddenException } from '@nestjs/common';
|
|
1
|
+
import { Module, Logger, applyDecorators, SetMetadata, HttpException, HttpStatus, BadRequestException, Injectable, Inject, NotFoundException, ForbiddenException } from '@nestjs/common';
|
|
2
2
|
import { MODULE_METADATA } from '@nestjs/common/constants';
|
|
3
3
|
import { pick } from 'lodash-es';
|
|
4
4
|
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
5
5
|
import { Subject, filter } from 'rxjs';
|
|
6
6
|
import { LanguagesEnum, AiModelTypeEnum, ParameterType, PriceType, FetchFrom, ModelFeature, ModelPropertyKey } from '@metad/contracts';
|
|
7
|
-
export { IColumnDef, IDSSchema, IDSTable, TDocumentAsset } from '@metad/contracts';
|
|
8
7
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
9
8
|
import { ExtractJwt } from 'passport-jwt';
|
|
10
9
|
import { verify, JsonWebTokenError } from 'jsonwebtoken';
|
|
@@ -38,11 +37,11 @@ import { getModelContextSize as getModelContextSize$1 } from '@langchain/core/la
|
|
|
38
37
|
* Metadata keys used in plugins for defining various aspects like entities, subscribers, and configurations.
|
|
39
38
|
*/ const PLUGIN_METADATA = {
|
|
40
39
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Key representing the entities registered within the plugin.
|
|
41
|
+
*/ ENTITIES: 'entities',
|
|
43
42
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
* Key representing event subscribers within the plugin.
|
|
44
|
+
*/ SUBSCRIBERS: 'subscribers'
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
/**
|
|
@@ -87,10 +86,10 @@ function _extends() {
|
|
|
87
86
|
function createPluginLogger(scope, baseMeta = {}) {
|
|
88
87
|
const nestLogger = new Logger(scope);
|
|
89
88
|
const wrap = (level, msg, meta)=>{
|
|
90
|
-
var
|
|
89
|
+
var // 保持与 Nest Logger 接口对齐
|
|
90
|
+
_nestLogger_level;
|
|
91
91
|
const payload = meta ? _extends({}, baseMeta, meta) : baseMeta;
|
|
92
|
-
(_nestLogger_level =
|
|
93
|
-
nestLogger[level]) == null ? void 0 : _nestLogger_level.call(nestLogger, msg + (Object.keys(payload).length ? ` ${JSON.stringify(payload)}` : ''));
|
|
92
|
+
(_nestLogger_level = nestLogger[level]) == null ? void 0 : _nestLogger_level.call(nestLogger, msg + (Object.keys(payload).length ? ` ${JSON.stringify(payload)}` : ''));
|
|
94
93
|
};
|
|
95
94
|
return {
|
|
96
95
|
child (meta) {
|
|
@@ -121,6 +120,8 @@ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedEr
|
|
|
121
120
|
};
|
|
122
121
|
|
|
123
122
|
// request-context.ts
|
|
123
|
+
const TENANT_SCOPE = 'tenant';
|
|
124
|
+
const ORGANIZATION_SCOPE = 'organization';
|
|
124
125
|
class RequestContext {
|
|
125
126
|
static currentRequestContext() {
|
|
126
127
|
const session = getRequestContext();
|
|
@@ -133,6 +134,11 @@ class RequestContext {
|
|
|
133
134
|
}
|
|
134
135
|
return null;
|
|
135
136
|
}
|
|
137
|
+
static currentApiKey() {
|
|
138
|
+
const user = RequestContext.currentUser();
|
|
139
|
+
var _user_apiKey;
|
|
140
|
+
return (_user_apiKey = user == null ? void 0 : user.apiKey) != null ? _user_apiKey : null;
|
|
141
|
+
}
|
|
136
142
|
static currentTenantId() {
|
|
137
143
|
const user = RequestContext.currentUser();
|
|
138
144
|
if (user) {
|
|
@@ -174,9 +180,9 @@ class RequestContext {
|
|
|
174
180
|
], throwError);
|
|
175
181
|
}
|
|
176
182
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
* Retrieves the language code from the headers of the current request.
|
|
184
|
+
* @returns The language code (LanguagesEnum) extracted from the headers, or the default language (ENGLISH) if not found.
|
|
185
|
+
*/ static getLanguageCode() {
|
|
180
186
|
// Retrieve the current request
|
|
181
187
|
const req = RequestContext.currentRequest();
|
|
182
188
|
// Variable to store the extracted language code
|
|
@@ -192,21 +198,71 @@ class RequestContext {
|
|
|
192
198
|
// Return the extracted language code or the default language (ENGLISH) if not found
|
|
193
199
|
return lang || LanguagesEnum.English;
|
|
194
200
|
}
|
|
195
|
-
static
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
static getScope() {
|
|
202
|
+
const request = this.currentRequest();
|
|
203
|
+
const user = this.currentUser();
|
|
204
|
+
var _user_tenantId, _ref;
|
|
205
|
+
const tenantId = (_ref = (_user_tenantId = user == null ? void 0 : user.tenantId) != null ? _user_tenantId : getHeaderValue(request, [
|
|
206
|
+
'tenant-id'
|
|
207
|
+
])) != null ? _ref : null;
|
|
208
|
+
var _getHeaderValue;
|
|
209
|
+
const organizationId = (_getHeaderValue = getHeaderValue(request, [
|
|
199
210
|
'organization-id'
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
211
|
+
])) != null ? _getHeaderValue : null;
|
|
212
|
+
const scopeLevelHeader = getHeaderValue(request, [
|
|
213
|
+
'x-scope-level'
|
|
214
|
+
]);
|
|
215
|
+
if (scopeLevelHeader) {
|
|
216
|
+
if (scopeLevelHeader !== TENANT_SCOPE && scopeLevelHeader !== ORGANIZATION_SCOPE) {
|
|
217
|
+
throw new BadRequestException(`Unsupported scope level: ${scopeLevelHeader}`);
|
|
218
|
+
}
|
|
219
|
+
if (scopeLevelHeader === TENANT_SCOPE) {
|
|
220
|
+
if (organizationId) {
|
|
221
|
+
throw new BadRequestException('Tenant scope requests must not include Organization-Id.');
|
|
206
222
|
}
|
|
223
|
+
return {
|
|
224
|
+
tenantId,
|
|
225
|
+
level: TENANT_SCOPE,
|
|
226
|
+
organizationId: null
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (!organizationId) {
|
|
230
|
+
throw new BadRequestException('Organization scope requests require Organization-Id.');
|
|
207
231
|
}
|
|
232
|
+
return {
|
|
233
|
+
tenantId,
|
|
234
|
+
level: ORGANIZATION_SCOPE,
|
|
235
|
+
organizationId
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
if (organizationId) {
|
|
239
|
+
return {
|
|
240
|
+
tenantId,
|
|
241
|
+
level: ORGANIZATION_SCOPE,
|
|
242
|
+
organizationId
|
|
243
|
+
};
|
|
208
244
|
}
|
|
209
|
-
return
|
|
245
|
+
return {
|
|
246
|
+
tenantId,
|
|
247
|
+
level: TENANT_SCOPE,
|
|
248
|
+
organizationId: null
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
static getOrganizationId() {
|
|
252
|
+
return this.getScope().organizationId;
|
|
253
|
+
}
|
|
254
|
+
static isTenantScope() {
|
|
255
|
+
return this.getScope().level === TENANT_SCOPE;
|
|
256
|
+
}
|
|
257
|
+
static isOrganizationScope() {
|
|
258
|
+
return this.getScope().level === ORGANIZATION_SCOPE;
|
|
259
|
+
}
|
|
260
|
+
static requireOrganizationScope() {
|
|
261
|
+
const scope = this.getScope();
|
|
262
|
+
if (scope.level !== ORGANIZATION_SCOPE || !scope.organizationId) {
|
|
263
|
+
throw new BadRequestException('Organization scope is required for this operation.');
|
|
264
|
+
}
|
|
265
|
+
return scope.organizationId;
|
|
210
266
|
}
|
|
211
267
|
static hasPermissions(findPermissions, throwError) {
|
|
212
268
|
const requestContext = RequestContext.currentRequestContext();
|
|
@@ -260,22 +316,22 @@ class RequestContext {
|
|
|
260
316
|
return null;
|
|
261
317
|
}
|
|
262
318
|
/**
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
319
|
+
* Checks if the current user has a specific role.
|
|
320
|
+
* @param {RolesEnum} role - The role to check.
|
|
321
|
+
* @param {boolean} throwError - Flag indicating whether to throw an error if the role is not granted.
|
|
322
|
+
* @returns {boolean} - True if the user has the role, otherwise false.
|
|
323
|
+
*/ static hasRole(role, throwError) {
|
|
268
324
|
return this.hasRoles([
|
|
269
325
|
role
|
|
270
326
|
], throwError);
|
|
271
327
|
}
|
|
272
328
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
329
|
+
* Checks if the current request context has any of the specified roles.
|
|
330
|
+
*
|
|
331
|
+
* @param roles - An array of roles to check.
|
|
332
|
+
* @param throwError - Whether to throw an error if no roles are found.
|
|
333
|
+
* @returns True if any of the required roles are found, otherwise false.
|
|
334
|
+
*/ static hasRoles(roles, throwError) {
|
|
279
335
|
const context = RequestContext.currentRequestContext();
|
|
280
336
|
if (context) {
|
|
281
337
|
try {
|
|
@@ -312,8 +368,23 @@ const als = new AsyncLocalStorage();
|
|
|
312
368
|
function getRequestContext() {
|
|
313
369
|
return als.getStore();
|
|
314
370
|
}
|
|
371
|
+
function getHeaderValue(req, keys) {
|
|
372
|
+
if (!(req == null ? void 0 : req.headers)) {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
for (const key of keys){
|
|
376
|
+
const value = req.headers[key];
|
|
377
|
+
if (Array.isArray(value)) {
|
|
378
|
+
var _value_;
|
|
379
|
+
return (_value_ = value[0]) != null ? _value_ : null;
|
|
380
|
+
}
|
|
381
|
+
if (typeof value === 'string' && value) {
|
|
382
|
+
return value;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
315
387
|
|
|
316
|
-
// request-context.middleware.ts
|
|
317
388
|
let RequestContextMiddleware = class RequestContextMiddleware {
|
|
318
389
|
use(req, _res, next) {
|
|
319
390
|
var _req_user;
|
|
@@ -414,10 +485,10 @@ class BaseStrategyRegistry {
|
|
|
414
485
|
}
|
|
415
486
|
/**
|
|
416
487
|
* Get strategy by type from the given organization including global strategies as fallback.
|
|
417
|
-
*
|
|
418
|
-
* @param type
|
|
419
|
-
* @param organizationId
|
|
420
|
-
* @returns
|
|
488
|
+
*
|
|
489
|
+
* @param type
|
|
490
|
+
* @param organizationId
|
|
491
|
+
* @returns
|
|
421
492
|
*/ get(type, organizationId) {
|
|
422
493
|
var _this_strategies_get, _this_strategies_get1;
|
|
423
494
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
@@ -431,34 +502,42 @@ class BaseStrategyRegistry {
|
|
|
431
502
|
}
|
|
432
503
|
/**
|
|
433
504
|
* List all strategies for the given organization including global strategies, or only global strategies if global org is specified.
|
|
434
|
-
*
|
|
435
|
-
* @param organizationId
|
|
436
|
-
* @returns
|
|
505
|
+
*
|
|
506
|
+
* @param organizationId
|
|
507
|
+
* @returns
|
|
437
508
|
*/ list(organizationId) {
|
|
438
|
-
var _this_strategies_get
|
|
509
|
+
var _this_strategies_get;
|
|
439
510
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
440
511
|
const orgKey = this.resolveOrganization(organizationId);
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
512
|
+
const effective = new Map();
|
|
513
|
+
var _this_strategies_get_entries;
|
|
514
|
+
for (const [type, strategy] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(orgKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
515
|
+
effective.set(type, strategy);
|
|
516
|
+
}
|
|
517
|
+
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
518
|
+
var _this_strategies_get1;
|
|
519
|
+
var _this_strategies_get_entries1;
|
|
520
|
+
for (const [type, strategy] of (_this_strategies_get_entries1 = (_this_strategies_get1 = this.strategies.get(GLOBAL_ORGANIZATION_SCOPE)) == null ? void 0 : _this_strategies_get1.entries()) != null ? _this_strategies_get_entries1 : []){
|
|
521
|
+
if (!effective.has(type)) {
|
|
522
|
+
effective.set(type, strategy);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return Array.from(effective.values());
|
|
449
527
|
}
|
|
450
528
|
constructor(strategyKey, discoveryService, reflector){
|
|
451
|
-
this.strategyKey = strategyKey;
|
|
452
|
-
this.discoveryService = discoveryService;
|
|
453
|
-
this.reflector = reflector;
|
|
454
529
|
this.logger = new Logger(BaseStrategyRegistry.name);
|
|
530
|
+
// Map<organizationId, Map<type, strategy>>
|
|
455
531
|
this.strategies = new Map();
|
|
456
532
|
this.pluginStrategies = new Map();
|
|
533
|
+
this.strategyKey = strategyKey;
|
|
534
|
+
this.discoveryService = discoveryService;
|
|
535
|
+
this.reflector = reflector;
|
|
457
536
|
}
|
|
458
537
|
}
|
|
459
538
|
__decorate([
|
|
460
539
|
Inject(StrategyBus),
|
|
461
|
-
__metadata("design:type",
|
|
540
|
+
__metadata("design:type", StrategyBus)
|
|
462
541
|
], BaseStrategyRegistry.prototype, "bus", void 0);
|
|
463
542
|
|
|
464
543
|
let IntegrationStrategyRegistry = class IntegrationStrategyRegistry extends BaseStrategyRegistry {
|
|
@@ -468,10 +547,9 @@ let IntegrationStrategyRegistry = class IntegrationStrategyRegistry extends Base
|
|
|
468
547
|
};
|
|
469
548
|
IntegrationStrategyRegistry = __decorate([
|
|
470
549
|
Injectable(),
|
|
471
|
-
__metadata("design:type", Function),
|
|
472
550
|
__metadata("design:paramtypes", [
|
|
473
|
-
|
|
474
|
-
|
|
551
|
+
DiscoveryService,
|
|
552
|
+
Reflector
|
|
475
553
|
])
|
|
476
554
|
], IntegrationStrategyRegistry);
|
|
477
555
|
|
|
@@ -485,10 +563,9 @@ let WorkflowTriggerRegistry = class WorkflowTriggerRegistry extends BaseStrategy
|
|
|
485
563
|
};
|
|
486
564
|
WorkflowTriggerRegistry = __decorate([
|
|
487
565
|
Injectable(),
|
|
488
|
-
__metadata("design:type", Function),
|
|
489
566
|
__metadata("design:paramtypes", [
|
|
490
|
-
|
|
491
|
-
|
|
567
|
+
DiscoveryService,
|
|
568
|
+
Reflector
|
|
492
569
|
])
|
|
493
570
|
], WorkflowTriggerRegistry);
|
|
494
571
|
|
|
@@ -497,21 +574,22 @@ const WORKFLOW_NODE_STRATEGY = 'WORKFLOW_NODE_STRATEGY';
|
|
|
497
574
|
* Decorator to mark a provider as a Workflow Node Strategy
|
|
498
575
|
*/ const WorkflowNodeStrategy = (provider)=>applyDecorators(SetMetadata(WORKFLOW_NODE_STRATEGY, provider), SetMetadata(STRATEGY_META_KEY, WORKFLOW_NODE_STRATEGY));
|
|
499
576
|
|
|
500
|
-
|
|
577
|
+
/**
|
|
578
|
+
* Registry for Workflow Node Strategies
|
|
579
|
+
*/ let WorkflowNodeRegistry = class WorkflowNodeRegistry extends BaseStrategyRegistry {
|
|
501
580
|
constructor(discoveryService, reflector){
|
|
502
581
|
super(WORKFLOW_NODE_STRATEGY, discoveryService, reflector);
|
|
503
582
|
}
|
|
504
583
|
};
|
|
505
584
|
WorkflowNodeRegistry = __decorate([
|
|
506
585
|
Injectable(),
|
|
507
|
-
__metadata("design:type", Function),
|
|
508
586
|
__metadata("design:paramtypes", [
|
|
509
|
-
|
|
510
|
-
|
|
587
|
+
DiscoveryService,
|
|
588
|
+
Reflector
|
|
511
589
|
])
|
|
512
590
|
], WorkflowNodeRegistry);
|
|
513
591
|
|
|
514
|
-
const COMMAND_METADATA$
|
|
592
|
+
const COMMAND_METADATA$2 = '__command__';
|
|
515
593
|
/**
|
|
516
594
|
* Wrap Workflow Node Execution Command
|
|
517
595
|
*/ class WrapWorkflowNodeExecutionCommand extends Command {
|
|
@@ -522,7 +600,7 @@ const COMMAND_METADATA$1 = '__command__';
|
|
|
522
600
|
}
|
|
523
601
|
}
|
|
524
602
|
WrapWorkflowNodeExecutionCommand.type = '[Workflow] Wrap Workflow Node Execution';
|
|
525
|
-
Reflect.defineMetadata(COMMAND_METADATA$
|
|
603
|
+
Reflect.defineMetadata(COMMAND_METADATA$2, {
|
|
526
604
|
id: WrapWorkflowNodeExecutionCommand.type
|
|
527
605
|
}, WrapWorkflowNodeExecutionCommand);
|
|
528
606
|
|
|
@@ -536,10 +614,9 @@ let VectorStoreRegistry = class VectorStoreRegistry extends BaseStrategyRegistry
|
|
|
536
614
|
};
|
|
537
615
|
VectorStoreRegistry = __decorate([
|
|
538
616
|
Injectable(),
|
|
539
|
-
__metadata("design:type", Function),
|
|
540
617
|
__metadata("design:paramtypes", [
|
|
541
|
-
|
|
542
|
-
|
|
618
|
+
DiscoveryService,
|
|
619
|
+
Reflector
|
|
543
620
|
])
|
|
544
621
|
], VectorStoreRegistry);
|
|
545
622
|
|
|
@@ -553,10 +630,9 @@ let TextSplitterRegistry = class TextSplitterRegistry extends BaseStrategyRegist
|
|
|
553
630
|
};
|
|
554
631
|
TextSplitterRegistry = __decorate([
|
|
555
632
|
Injectable(),
|
|
556
|
-
__metadata("design:type", Function),
|
|
557
633
|
__metadata("design:paramtypes", [
|
|
558
|
-
|
|
559
|
-
|
|
634
|
+
DiscoveryService,
|
|
635
|
+
Reflector
|
|
560
636
|
])
|
|
561
637
|
], TextSplitterRegistry);
|
|
562
638
|
|
|
@@ -572,10 +648,9 @@ let DocumentSourceRegistry = class DocumentSourceRegistry extends BaseStrategyRe
|
|
|
572
648
|
};
|
|
573
649
|
DocumentSourceRegistry = __decorate([
|
|
574
650
|
Injectable(),
|
|
575
|
-
__metadata("design:type", Function),
|
|
576
651
|
__metadata("design:paramtypes", [
|
|
577
|
-
|
|
578
|
-
|
|
652
|
+
DiscoveryService,
|
|
653
|
+
Reflector
|
|
579
654
|
])
|
|
580
655
|
], DocumentSourceRegistry);
|
|
581
656
|
|
|
@@ -591,10 +666,9 @@ let DocumentTransformerRegistry = class DocumentTransformerRegistry extends Base
|
|
|
591
666
|
};
|
|
592
667
|
DocumentTransformerRegistry = __decorate([
|
|
593
668
|
Injectable(),
|
|
594
|
-
__metadata("design:type", Function),
|
|
595
669
|
__metadata("design:paramtypes", [
|
|
596
|
-
|
|
597
|
-
|
|
670
|
+
DiscoveryService,
|
|
671
|
+
Reflector
|
|
598
672
|
])
|
|
599
673
|
], DocumentTransformerRegistry);
|
|
600
674
|
|
|
@@ -610,16 +684,15 @@ let RetrieverRegistry = class RetrieverRegistry extends BaseStrategyRegistry {
|
|
|
610
684
|
};
|
|
611
685
|
RetrieverRegistry = __decorate([
|
|
612
686
|
Injectable(),
|
|
613
|
-
__metadata("design:type", Function),
|
|
614
687
|
__metadata("design:paramtypes", [
|
|
615
|
-
|
|
616
|
-
|
|
688
|
+
DiscoveryService,
|
|
689
|
+
Reflector
|
|
617
690
|
])
|
|
618
691
|
], RetrieverRegistry);
|
|
619
692
|
|
|
620
693
|
/**
|
|
621
694
|
* Merge parent chunks with their child chunks based on metadata (parentId and chunkId)
|
|
622
|
-
*
|
|
695
|
+
*
|
|
623
696
|
* @deprecated use buildChunkTreeAndFindLeaves instead
|
|
624
697
|
*/ function mergeParentChildChunks(chunks, children // Child chunks
|
|
625
698
|
) {
|
|
@@ -685,10 +758,9 @@ let ImageUnderstandingRegistry = class ImageUnderstandingRegistry extends BaseSt
|
|
|
685
758
|
};
|
|
686
759
|
ImageUnderstandingRegistry = __decorate([
|
|
687
760
|
Injectable(),
|
|
688
|
-
__metadata("design:type", Function),
|
|
689
761
|
__metadata("design:paramtypes", [
|
|
690
|
-
|
|
691
|
-
|
|
762
|
+
DiscoveryService,
|
|
763
|
+
Reflector
|
|
692
764
|
])
|
|
693
765
|
], ImageUnderstandingRegistry);
|
|
694
766
|
|
|
@@ -702,10 +774,9 @@ let KnowledgeStrategyRegistry = class KnowledgeStrategyRegistry extends BaseStra
|
|
|
702
774
|
};
|
|
703
775
|
KnowledgeStrategyRegistry = __decorate([
|
|
704
776
|
Injectable(),
|
|
705
|
-
__metadata("design:type", Function),
|
|
706
777
|
__metadata("design:paramtypes", [
|
|
707
|
-
|
|
708
|
-
|
|
778
|
+
DiscoveryService,
|
|
779
|
+
Reflector
|
|
709
780
|
])
|
|
710
781
|
], KnowledgeStrategyRegistry);
|
|
711
782
|
|
|
@@ -721,10 +792,9 @@ let ToolsetRegistry = class ToolsetRegistry extends BaseStrategyRegistry {
|
|
|
721
792
|
};
|
|
722
793
|
ToolsetRegistry = __decorate([
|
|
723
794
|
Injectable(),
|
|
724
|
-
__metadata("design:type", Function),
|
|
725
795
|
__metadata("design:paramtypes", [
|
|
726
|
-
|
|
727
|
-
|
|
796
|
+
DiscoveryService,
|
|
797
|
+
Reflector
|
|
728
798
|
])
|
|
729
799
|
], ToolsetRegistry);
|
|
730
800
|
|
|
@@ -732,26 +802,26 @@ ToolsetRegistry = __decorate([
|
|
|
732
802
|
* Base ability for all toolsets
|
|
733
803
|
*/ class BaseToolset extends BaseToolkit {
|
|
734
804
|
/**
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
805
|
+
* Async init tools
|
|
806
|
+
*
|
|
807
|
+
* @returns
|
|
808
|
+
*/ async initTools() {
|
|
739
809
|
return this.tools;
|
|
740
810
|
}
|
|
741
811
|
/**
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
812
|
+
* Get one tool
|
|
813
|
+
*
|
|
814
|
+
* @param toolName
|
|
815
|
+
* @returns
|
|
816
|
+
*/ getTool(toolName) {
|
|
747
817
|
var _this_getTools;
|
|
748
818
|
return (_this_getTools = this.getTools()) == null ? void 0 : _this_getTools.find((tool)=>tool.name === toolName);
|
|
749
819
|
}
|
|
750
820
|
/**
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
821
|
+
* Get state variables config
|
|
822
|
+
*
|
|
823
|
+
* @returns State variables
|
|
824
|
+
*/ async getVariables() {
|
|
755
825
|
return null;
|
|
756
826
|
}
|
|
757
827
|
/**
|
|
@@ -809,26 +879,26 @@ class BuiltinToolset extends BaseToolset {
|
|
|
809
879
|
return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.credentials;
|
|
810
880
|
}
|
|
811
881
|
getToolTitle(name) {
|
|
812
|
-
var _this_toolset_tools, _this_toolset,
|
|
882
|
+
var _this_toolset_tools, _this_toolset, _tool_schema;
|
|
813
883
|
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);
|
|
814
|
-
const identity =
|
|
884
|
+
const identity = tool == null ? void 0 : (_tool_schema = tool.schema) == null ? void 0 : _tool_schema.identity;
|
|
815
885
|
if (identity) {
|
|
816
886
|
return identity.label;
|
|
817
887
|
}
|
|
818
888
|
return null;
|
|
819
889
|
}
|
|
820
890
|
/**
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
891
|
+
* Get credentials schema
|
|
892
|
+
*
|
|
893
|
+
* @returns Credentials schema
|
|
894
|
+
*/ getCredentialsSchema() {
|
|
825
895
|
return _extends({}, this.credentialsSchema);
|
|
826
896
|
}
|
|
827
897
|
/**
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
898
|
+
* Get toolset entity
|
|
899
|
+
*
|
|
900
|
+
* @returns XpertToolset
|
|
901
|
+
*/ getToolset() {
|
|
832
902
|
return this.toolset;
|
|
833
903
|
}
|
|
834
904
|
getName() {
|
|
@@ -837,27 +907,27 @@ class BuiltinToolset extends BaseToolset {
|
|
|
837
907
|
}
|
|
838
908
|
constructor(providerName, toolset, params){
|
|
839
909
|
super(params);
|
|
910
|
+
this.logger = new Logger(this.constructor.name);
|
|
840
911
|
this.providerName = providerName;
|
|
841
912
|
this.toolset = toolset;
|
|
842
913
|
this.params = params;
|
|
843
|
-
this.logger = new Logger(this.constructor.name);
|
|
844
914
|
}
|
|
845
|
-
}
|
|
915
|
+
}
|
|
846
916
|
BuiltinToolset.provider = '';
|
|
847
917
|
|
|
848
918
|
/**
|
|
849
919
|
* Restricted FileSystem based on granted permissions
|
|
850
920
|
*/ class XpFileSystem {
|
|
851
921
|
/**
|
|
852
|
-
|
|
853
|
-
|
|
922
|
+
* Check if operation is allowed
|
|
923
|
+
*/ ensureAllowed(op) {
|
|
854
924
|
if (!this.allowedOps.has(op)) {
|
|
855
925
|
throw new Error(`Permission denied: ${op} operation not allowed`);
|
|
856
926
|
}
|
|
857
927
|
}
|
|
858
928
|
/**
|
|
859
|
-
|
|
860
|
-
|
|
929
|
+
* Check if path is within scope
|
|
930
|
+
*/ ensureInScope(targetPath) {
|
|
861
931
|
if (!this.scope || this.scope.length === 0) return;
|
|
862
932
|
const resolved = path__default.resolve(targetPath);
|
|
863
933
|
for (const s of this.scope){
|
|
@@ -867,33 +937,33 @@ BuiltinToolset.provider = '';
|
|
|
867
937
|
throw new Error(`Permission denied: path "${targetPath}" is out of scope`);
|
|
868
938
|
}
|
|
869
939
|
/**
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
940
|
+
* Get the absolute path of file in the file system.
|
|
941
|
+
*
|
|
942
|
+
* @param filePath Relative file path
|
|
943
|
+
* @returns Absolute file path
|
|
944
|
+
*/ fullPath(filePath) {
|
|
875
945
|
return path__default.join(this.basePath, filePath);
|
|
876
946
|
}
|
|
877
947
|
/**
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
948
|
+
* Get web url for a given file path in the file system.
|
|
949
|
+
*
|
|
950
|
+
* @param filePath Relative file path
|
|
951
|
+
* @returns Web URL of file
|
|
952
|
+
*/ fullUrl(filePath) {
|
|
883
953
|
const url = new URL(filePath, this.baseUrl);
|
|
884
954
|
return url.href;
|
|
885
955
|
}
|
|
886
956
|
/**
|
|
887
|
-
|
|
888
|
-
|
|
957
|
+
* Read file contents
|
|
958
|
+
*/ async readFile(filePath, encoding = 'utf-8') {
|
|
889
959
|
this.ensureAllowed('read');
|
|
890
960
|
const fullPath = this.fullPath(filePath);
|
|
891
961
|
this.ensureInScope(fullPath);
|
|
892
962
|
return await fsPromises.readFile(fullPath);
|
|
893
963
|
}
|
|
894
964
|
/**
|
|
895
|
-
|
|
896
|
-
|
|
965
|
+
* Write file contents
|
|
966
|
+
*/ async writeFile(filePath, content) {
|
|
897
967
|
this.ensureAllowed('write');
|
|
898
968
|
const fullPath = this.fullPath(filePath);
|
|
899
969
|
this.ensureInScope(fullPath);
|
|
@@ -905,22 +975,22 @@ BuiltinToolset.provider = '';
|
|
|
905
975
|
return url.href;
|
|
906
976
|
}
|
|
907
977
|
/**
|
|
908
|
-
|
|
909
|
-
|
|
978
|
+
* Delete a file
|
|
979
|
+
*/ async deleteFile(filePath) {
|
|
910
980
|
this.ensureAllowed('delete');
|
|
911
981
|
this.ensureInScope(filePath);
|
|
912
982
|
await fsPromises.unlink(filePath);
|
|
913
983
|
}
|
|
914
984
|
/**
|
|
915
|
-
|
|
916
|
-
|
|
985
|
+
* List directory contents
|
|
986
|
+
*/ async listDir(dirPath) {
|
|
917
987
|
this.ensureAllowed('list');
|
|
918
988
|
this.ensureInScope(dirPath);
|
|
919
989
|
return fsPromises.readdir(dirPath);
|
|
920
990
|
}
|
|
921
991
|
/**
|
|
922
|
-
|
|
923
|
-
|
|
992
|
+
* Utility: check if a file or directory exists
|
|
993
|
+
*/ async exists(targetPath) {
|
|
924
994
|
try {
|
|
925
995
|
await fsPromises.access(targetPath);
|
|
926
996
|
return true;
|
|
@@ -1027,7 +1097,7 @@ function loadYamlFile(filePath, logger, ignoreError = true, defaultValue = {}) {
|
|
|
1027
1097
|
}
|
|
1028
1098
|
/**
|
|
1029
1099
|
* Get the mapping from name to index from a YAML file
|
|
1030
|
-
*
|
|
1100
|
+
*
|
|
1031
1101
|
* @param folderPath
|
|
1032
1102
|
* @param fileName the YAML file name, default to '_position.yaml'
|
|
1033
1103
|
* @return a dict with name as key and index as value
|
|
@@ -1096,10 +1166,9 @@ let DataSourceStrategyRegistry = class DataSourceStrategyRegistry extends BaseSt
|
|
|
1096
1166
|
};
|
|
1097
1167
|
DataSourceStrategyRegistry = __decorate([
|
|
1098
1168
|
Injectable(),
|
|
1099
|
-
__metadata("design:type", Function),
|
|
1100
1169
|
__metadata("design:paramtypes", [
|
|
1101
|
-
|
|
1102
|
-
|
|
1170
|
+
DiscoveryService,
|
|
1171
|
+
Reflector
|
|
1103
1172
|
])
|
|
1104
1173
|
], DataSourceStrategyRegistry);
|
|
1105
1174
|
|
|
@@ -1108,12 +1177,12 @@ DataSourceStrategyRegistry = __decorate([
|
|
|
1108
1177
|
* into datasource strategies consumable by the plugin SDK.
|
|
1109
1178
|
*/ class AdapterDataSourceStrategy {
|
|
1110
1179
|
/**
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1180
|
+
* Get from cache or create new instance of DB adapter.
|
|
1181
|
+
*
|
|
1182
|
+
* @param options
|
|
1183
|
+
* @param id
|
|
1184
|
+
* @returns
|
|
1185
|
+
*/ async create(options, id) {
|
|
1117
1186
|
if (id) {
|
|
1118
1187
|
if (this.runners.has(id)) {
|
|
1119
1188
|
return this.runners.get(id);
|
|
@@ -1149,9 +1218,10 @@ DataSourceStrategyRegistry = __decorate([
|
|
|
1149
1218
|
return this.runnerClass;
|
|
1150
1219
|
}
|
|
1151
1220
|
constructor(runnerClass, extraArgs = []){
|
|
1221
|
+
this.runners = new Map() // dataSourceId -> runner instance
|
|
1222
|
+
;
|
|
1152
1223
|
this.runnerClass = runnerClass;
|
|
1153
1224
|
this.extraArgs = extraArgs;
|
|
1154
|
-
this.runners = new Map();
|
|
1155
1225
|
}
|
|
1156
1226
|
}
|
|
1157
1227
|
|
|
@@ -1251,13 +1321,13 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1251
1321
|
await this.runQuery(`SELECT 1`);
|
|
1252
1322
|
}
|
|
1253
1323
|
/**
|
|
1254
|
-
|
|
1255
|
-
|
|
1324
|
+
* Default implementation for table operations
|
|
1325
|
+
*/ async tableOp(action, params, options) {
|
|
1256
1326
|
switch(action){
|
|
1257
|
-
case
|
|
1327
|
+
case DBTableAction.CREATE_TABLE:
|
|
1258
1328
|
{
|
|
1259
1329
|
// Default implementation for creating table (generic SQL syntax)
|
|
1260
|
-
const { schema, table, columns, createMode =
|
|
1330
|
+
const { schema, table, columns, createMode = DBCreateTableMode.ERROR } = params;
|
|
1261
1331
|
const tableName = schema ? `${schema}.${table}` : table;
|
|
1262
1332
|
// Check if table exists (try to query table info)
|
|
1263
1333
|
let exists = false;
|
|
@@ -1269,17 +1339,17 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1269
1339
|
exists = false;
|
|
1270
1340
|
}
|
|
1271
1341
|
// --- MODE: ERROR → throw error if table exists ---
|
|
1272
|
-
if (exists && createMode ===
|
|
1342
|
+
if (exists && createMode === DBCreateTableMode.ERROR) {
|
|
1273
1343
|
throw new Error(`Table "${tableName}" already exists`);
|
|
1274
1344
|
}
|
|
1275
1345
|
// --- MODE: IGNORE → do nothing if exists ---
|
|
1276
|
-
if (exists && createMode ===
|
|
1346
|
+
if (exists && createMode === DBCreateTableMode.IGNORE) {
|
|
1277
1347
|
return;
|
|
1278
1348
|
}
|
|
1279
1349
|
// --- MODE: UPGRADE → auto upgrade (simple implementation: only add new columns) ---
|
|
1280
1350
|
// Note: This default implementation does not support modifying column types,
|
|
1281
1351
|
// recommend each database to implement its own version
|
|
1282
|
-
if (exists && createMode ===
|
|
1352
|
+
if (exists && createMode === DBCreateTableMode.UPGRADE) {
|
|
1283
1353
|
console.warn(`[BaseSQLQueryRunner] UPGRADE mode uses basic implementation. Consider implementing tableOp for better support.`);
|
|
1284
1354
|
// Try to add new columns (will fail if column already exists, but doesn't affect)
|
|
1285
1355
|
for (const col of columns){
|
|
@@ -1304,7 +1374,7 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1304
1374
|
await this.runQuery(createTableStatement, options);
|
|
1305
1375
|
return;
|
|
1306
1376
|
}
|
|
1307
|
-
case
|
|
1377
|
+
case DBTableAction.DROP_TABLE:
|
|
1308
1378
|
{
|
|
1309
1379
|
// Default implementation for dropping table
|
|
1310
1380
|
const { schema, table } = params;
|
|
@@ -1318,8 +1388,8 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1318
1388
|
}
|
|
1319
1389
|
}
|
|
1320
1390
|
/**
|
|
1321
|
-
|
|
1322
|
-
|
|
1391
|
+
* Generic type mapping (subclasses can override)
|
|
1392
|
+
*/ mapColumnType(type, isKey, length) {
|
|
1323
1393
|
switch(type == null ? void 0 : type.toLowerCase()){
|
|
1324
1394
|
case 'string':
|
|
1325
1395
|
return length ? `VARCHAR(${length})` : isKey ? 'VARCHAR(255)' : 'VARCHAR(1000)';
|
|
@@ -1339,8 +1409,8 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1339
1409
|
}
|
|
1340
1410
|
constructor(...args){
|
|
1341
1411
|
super(...args);
|
|
1342
|
-
this.syntax =
|
|
1343
|
-
this.protocol =
|
|
1412
|
+
this.syntax = DBSyntaxEnum.SQL;
|
|
1413
|
+
this.protocol = DBProtocolEnum.SQL;
|
|
1344
1414
|
}
|
|
1345
1415
|
}
|
|
1346
1416
|
var DBTableAction;
|
|
@@ -1361,7 +1431,9 @@ var DBTableAction;
|
|
|
1361
1431
|
DBTableAction["CLONE_TABLE"] = "cloneTable";
|
|
1362
1432
|
DBTableAction["OPTIMIZE_TABLE"] = "optimizeTable";
|
|
1363
1433
|
})(DBTableAction || (DBTableAction = {}));
|
|
1364
|
-
|
|
1434
|
+
/**
|
|
1435
|
+
* Modes for creating a table, if the table already exists
|
|
1436
|
+
*/ var DBCreateTableMode;
|
|
1365
1437
|
(function(DBCreateTableMode) {
|
|
1366
1438
|
DBCreateTableMode["ERROR"] = "error";
|
|
1367
1439
|
DBCreateTableMode["IGNORE"] = "ignore";
|
|
@@ -1391,8 +1463,7 @@ function AIModelProviderStrategy(provider) {
|
|
|
1391
1463
|
const match = (callerLine == null ? void 0 : callerLine.match(/\((file:\/\/\/[^\s)]+)\)/)) || (// case 1: file:///path...
|
|
1392
1464
|
callerLine == null ? void 0 : callerLine.match(/\((\/[^\s)]+)\)/)) || (// case 2: (/Users/xxx)
|
|
1393
1465
|
callerLine == null ? void 0 : callerLine.match(/at (file:\/\/\/[^\s]+)/)) || (// case 3: at file:///...
|
|
1394
|
-
callerLine == null ? void 0 : callerLine.match(/at (\/[^\s]+)/) // case 4: at /Users/xxx
|
|
1395
|
-
);
|
|
1466
|
+
callerLine == null ? void 0 : callerLine.match(/at (\/[^\s]+)/)); // case 4: at /Users/xxx
|
|
1396
1467
|
let file = match == null ? void 0 : match[1];
|
|
1397
1468
|
// remove the file:/// prefix
|
|
1398
1469
|
if (file == null ? void 0 : file.startsWith('file:///')) {
|
|
@@ -1427,10 +1498,9 @@ let AIModelProviderRegistry = class AIModelProviderRegistry extends BaseStrategy
|
|
|
1427
1498
|
};
|
|
1428
1499
|
AIModelProviderRegistry = __decorate([
|
|
1429
1500
|
Injectable(),
|
|
1430
|
-
__metadata("design:type", Function),
|
|
1431
1501
|
__metadata("design:paramtypes", [
|
|
1432
|
-
|
|
1433
|
-
|
|
1502
|
+
DiscoveryService,
|
|
1503
|
+
Reflector
|
|
1434
1504
|
])
|
|
1435
1505
|
], AIModelProviderRegistry);
|
|
1436
1506
|
|
|
@@ -1441,7 +1511,8 @@ class CredentialsValidateFailedError extends ForbiddenException {
|
|
|
1441
1511
|
class AIModelProviderNotFoundException extends NotFoundException {
|
|
1442
1512
|
}
|
|
1443
1513
|
|
|
1444
|
-
|
|
1514
|
+
var ModelProvider_1;
|
|
1515
|
+
let ModelProvider = ModelProvider_1 = class ModelProvider {
|
|
1445
1516
|
get name() {
|
|
1446
1517
|
return this.getProviderSchema().provider;
|
|
1447
1518
|
}
|
|
@@ -1449,10 +1520,10 @@ let ModelProvider = class ModelProvider {
|
|
|
1449
1520
|
await this.validateProviderCredentials(credentials);
|
|
1450
1521
|
}
|
|
1451
1522
|
/**
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1523
|
+
* Get provider lib root path.
|
|
1524
|
+
*
|
|
1525
|
+
* @returns Root of library
|
|
1526
|
+
*/ getProviderServerPath() {
|
|
1456
1527
|
return this.dir;
|
|
1457
1528
|
}
|
|
1458
1529
|
getProviderSchema() {
|
|
@@ -1487,11 +1558,11 @@ let ModelProvider = class ModelProvider {
|
|
|
1487
1558
|
return modelInstance;
|
|
1488
1559
|
}
|
|
1489
1560
|
/**
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1561
|
+
* Get provider models.
|
|
1562
|
+
* @param modelType - model type
|
|
1563
|
+
* @param onlyActive - only active models
|
|
1564
|
+
* @return provider models
|
|
1565
|
+
*/ getProviderModels(modelType, onlyActive = false) {
|
|
1495
1566
|
let modelTypes = [];
|
|
1496
1567
|
if (modelType) {
|
|
1497
1568
|
modelTypes.push(modelType);
|
|
@@ -1543,7 +1614,7 @@ let ModelProvider = class ModelProvider {
|
|
|
1543
1614
|
return null;
|
|
1544
1615
|
}
|
|
1545
1616
|
constructor(){
|
|
1546
|
-
this.logger = new Logger(
|
|
1617
|
+
this.logger = new Logger(ModelProvider_1.name);
|
|
1547
1618
|
// protected providerSchema: IAiProviderEntity | null = null
|
|
1548
1619
|
this.modelManagers = new Map();
|
|
1549
1620
|
const provider = Reflect.getMetadata(AI_MODEL_PROVIDER, this.constructor);
|
|
@@ -1553,9 +1624,8 @@ let ModelProvider = class ModelProvider {
|
|
|
1553
1624
|
this.dir = dir;
|
|
1554
1625
|
}
|
|
1555
1626
|
};
|
|
1556
|
-
ModelProvider = __decorate([
|
|
1627
|
+
ModelProvider = ModelProvider_1 = __decorate([
|
|
1557
1628
|
Injectable(),
|
|
1558
|
-
__metadata("design:type", Function),
|
|
1559
1629
|
__metadata("design:paramtypes", [])
|
|
1560
1630
|
], ModelProvider);
|
|
1561
1631
|
|
|
@@ -1744,7 +1814,8 @@ function mergeCredentials(credentials, modelProperties) {
|
|
|
1744
1814
|
return _extends({}, credentials != null ? credentials : {}, modelProperties != null ? modelProperties : {});
|
|
1745
1815
|
}
|
|
1746
1816
|
|
|
1747
|
-
|
|
1817
|
+
var AIModel_1;
|
|
1818
|
+
let AIModel = AIModel_1 = class AIModel {
|
|
1748
1819
|
getChatModel(copilotModel, options) {
|
|
1749
1820
|
throw new Error(`Unsupport chat model!`);
|
|
1750
1821
|
}
|
|
@@ -1819,13 +1890,13 @@ let AIModel = class AIModel {
|
|
|
1819
1890
|
return null;
|
|
1820
1891
|
}
|
|
1821
1892
|
/**
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1893
|
+
* Get customizable model schema.
|
|
1894
|
+
* Implement this method in ai model sub class that can customize model
|
|
1895
|
+
*
|
|
1896
|
+
* @param model model name
|
|
1897
|
+
* @param credentials model credentials
|
|
1898
|
+
* @returns model schema
|
|
1899
|
+
*/ getCustomizableModelSchemaFromCredentials(model, credentials) {
|
|
1829
1900
|
return null;
|
|
1830
1901
|
}
|
|
1831
1902
|
processParameterRules(yamlData) {
|
|
@@ -1897,29 +1968,28 @@ let AIModel = class AIModel {
|
|
|
1897
1968
|
};
|
|
1898
1969
|
}
|
|
1899
1970
|
constructor(modelProvider, modelType){
|
|
1900
|
-
this.
|
|
1901
|
-
this.modelType = modelType;
|
|
1902
|
-
this.logger = new Logger(AIModel.name);
|
|
1971
|
+
this.logger = new Logger(AIModel_1.name);
|
|
1903
1972
|
this.modelSchemas = null;
|
|
1904
1973
|
this.positions = null;
|
|
1974
|
+
this.modelProvider = modelProvider;
|
|
1975
|
+
this.modelType = modelType;
|
|
1905
1976
|
this.modelProvider.registerAIModelInstance(this.modelType, this);
|
|
1906
1977
|
}
|
|
1907
1978
|
};
|
|
1908
|
-
AIModel = __decorate([
|
|
1979
|
+
AIModel = AIModel_1 = __decorate([
|
|
1909
1980
|
Injectable(),
|
|
1910
|
-
__metadata("design:type", Function),
|
|
1911
1981
|
__metadata("design:paramtypes", [
|
|
1912
|
-
|
|
1913
|
-
|
|
1982
|
+
ModelProvider,
|
|
1983
|
+
String
|
|
1914
1984
|
])
|
|
1915
1985
|
], AIModel);
|
|
1916
1986
|
function getDefaultParameterRuleVariableMap(name) {
|
|
1917
1987
|
/**
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1988
|
+
* Get default parameter rule for given name
|
|
1989
|
+
*
|
|
1990
|
+
* @param name - parameter name
|
|
1991
|
+
* @return parameter rule
|
|
1992
|
+
*/ const defaultParameterRule = PARAMETER_RULE_TEMPLATE[name];
|
|
1923
1993
|
if (!defaultParameterRule) {
|
|
1924
1994
|
throw new Error(`Invalid model parameter rule name ${name}`);
|
|
1925
1995
|
}
|
|
@@ -1985,17 +2055,18 @@ function _class_private_field_loose_key(name) {
|
|
|
1985
2055
|
return "__private_" + id++ + "_" + name;
|
|
1986
2056
|
}
|
|
1987
2057
|
|
|
2058
|
+
var _a;
|
|
1988
2059
|
class LLMUsage {
|
|
1989
2060
|
static emptyUsage() {
|
|
1990
2061
|
return new LLMUsage(0, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 0.0, 0, 0.0, 'USD', 0.0);
|
|
1991
2062
|
}
|
|
1992
2063
|
plus(other) {
|
|
1993
2064
|
/**
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2065
|
+
* Add two LLMUsage instances together.
|
|
2066
|
+
*
|
|
2067
|
+
* @param other: Another LLMUsage instance to add
|
|
2068
|
+
* @return: A new LLMUsage instance with summed values
|
|
2069
|
+
*/ if (this.totalTokens === 0) {
|
|
1999
2070
|
return other;
|
|
2000
2071
|
} else {
|
|
2001
2072
|
return new LLMUsage(this.promptTokens + other.promptTokens, other.promptUnitPrice, other.promptPriceUnit, this.promptPrice + other.promptPrice, this.completionTokens + other.completionTokens, other.completionUnitPrice, other.completionPriceUnit, this.completionPrice + other.completionPrice, this.totalTokens + other.totalTokens, this.totalPrice + other.totalPrice, other.currency, this.latency + other.latency);
|
|
@@ -2003,11 +2074,11 @@ class LLMUsage {
|
|
|
2003
2074
|
}
|
|
2004
2075
|
add(other) {
|
|
2005
2076
|
/**
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2077
|
+
* Overload the + operator to add two LLMUsage instances.
|
|
2078
|
+
*
|
|
2079
|
+
* @param other: Another LLMUsage instance to add
|
|
2080
|
+
* @return: A new LLMUsage instance with summed values
|
|
2081
|
+
*/ return this.plus(other);
|
|
2011
2082
|
}
|
|
2012
2083
|
constructor(promptTokens, promptUnitPrice, promptPriceUnit, promptPrice, completionTokens, completionUnitPrice, completionPriceUnit, completionPrice, totalTokens, totalPrice, currency, latency){
|
|
2013
2084
|
this.promptTokens = promptTokens;
|
|
@@ -2127,15 +2198,88 @@ class LargeLanguageModel extends AIModel {
|
|
|
2127
2198
|
}
|
|
2128
2199
|
};
|
|
2129
2200
|
}
|
|
2201
|
+
createHandleVerboseCallbacks(enabled, logger) {
|
|
2202
|
+
if (!enabled) {
|
|
2203
|
+
return [];
|
|
2204
|
+
}
|
|
2205
|
+
const targetLogger = logger != null ? logger : _class_private_field_loose_base(this, _logger)[_logger];
|
|
2206
|
+
return [
|
|
2207
|
+
{
|
|
2208
|
+
handleChatModelStart: (llm, messages, runId, parentRunId, extraParams, tags, metadata, runName)=>{
|
|
2209
|
+
targetLogger.verbose(this.formatVerboseLog('chat_model/start', {
|
|
2210
|
+
runId,
|
|
2211
|
+
parentRunId,
|
|
2212
|
+
runName,
|
|
2213
|
+
model: llm,
|
|
2214
|
+
messages,
|
|
2215
|
+
extraParams,
|
|
2216
|
+
tags,
|
|
2217
|
+
metadata
|
|
2218
|
+
}));
|
|
2219
|
+
},
|
|
2220
|
+
handleLLMStart: (llm, prompts, runId, parentRunId, extraParams, tags, metadata, runName)=>{
|
|
2221
|
+
targetLogger.verbose(this.formatVerboseLog('llm/start', {
|
|
2222
|
+
runId,
|
|
2223
|
+
parentRunId,
|
|
2224
|
+
runName,
|
|
2225
|
+
model: llm,
|
|
2226
|
+
prompts,
|
|
2227
|
+
extraParams,
|
|
2228
|
+
tags,
|
|
2229
|
+
metadata
|
|
2230
|
+
}));
|
|
2231
|
+
},
|
|
2232
|
+
handleLLMEnd: (output, runId, parentRunId, tags, extraParams)=>{
|
|
2233
|
+
targetLogger.verbose(this.formatVerboseLog('llm/end', {
|
|
2234
|
+
runId,
|
|
2235
|
+
parentRunId,
|
|
2236
|
+
output,
|
|
2237
|
+
tags,
|
|
2238
|
+
extraParams
|
|
2239
|
+
}));
|
|
2240
|
+
},
|
|
2241
|
+
handleLLMError: (err, runId, parentRunId, tags, extraParams)=>{
|
|
2242
|
+
targetLogger.verbose(this.formatVerboseLog('llm/error', {
|
|
2243
|
+
runId,
|
|
2244
|
+
parentRunId,
|
|
2245
|
+
error: this.formatError(err),
|
|
2246
|
+
tags,
|
|
2247
|
+
extraParams
|
|
2248
|
+
}));
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
];
|
|
2252
|
+
}
|
|
2253
|
+
formatVerboseLog(event, payload) {
|
|
2254
|
+
return `[langchain][${event}] ${this.stringifyLogPayload(payload)}`;
|
|
2255
|
+
}
|
|
2256
|
+
stringifyLogPayload(payload) {
|
|
2257
|
+
try {
|
|
2258
|
+
return JSON.stringify(payload, null, 2);
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
return `[unserializable payload: ${this.formatError(error)}]`;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
formatError(error) {
|
|
2264
|
+
if (error instanceof Error) {
|
|
2265
|
+
return {
|
|
2266
|
+
name: error.name,
|
|
2267
|
+
message: error.message,
|
|
2268
|
+
stack: error.stack
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
return error;
|
|
2272
|
+
}
|
|
2130
2273
|
constructor(...args){
|
|
2131
2274
|
super(...args);
|
|
2132
2275
|
Object.defineProperty(this, _logger, {
|
|
2133
2276
|
writable: true,
|
|
2134
2277
|
value: void 0
|
|
2135
2278
|
});
|
|
2136
|
-
_class_private_field_loose_base(this, _logger)[_logger] = new Logger(
|
|
2279
|
+
_class_private_field_loose_base(this, _logger)[_logger] = new Logger(_a.name);
|
|
2137
2280
|
}
|
|
2138
2281
|
}
|
|
2282
|
+
_a = LargeLanguageModel;
|
|
2139
2283
|
function calcTokenUsage(output) {
|
|
2140
2284
|
var _output_generations;
|
|
2141
2285
|
const tokenUsage = {
|
|
@@ -2183,8 +2327,8 @@ function calcTokenUsage(output) {
|
|
|
2183
2327
|
* In this way, the reasoning process in the model output can be separated from the main content, making it easier for subsequent structured processing and display.
|
|
2184
2328
|
*/ class ChatOAICompatReasoningModel extends ChatOpenAICompletions {
|
|
2185
2329
|
/**
|
|
2186
|
-
|
|
2187
|
-
|
|
2330
|
+
*
|
|
2331
|
+
*/ _convertCompletionsDeltaToBaseMessageChunk(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2188
2332
|
delta, rawResponse, defaultRole) {
|
|
2189
2333
|
const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole);
|
|
2190
2334
|
if (delta['content'] === '<think>') {
|
|
@@ -2370,7 +2514,7 @@ function normalizeContextSize(value) {
|
|
|
2370
2514
|
return undefined;
|
|
2371
2515
|
}
|
|
2372
2516
|
|
|
2373
|
-
const COMMAND_METADATA = '__command__';
|
|
2517
|
+
const COMMAND_METADATA$1 = '__command__';
|
|
2374
2518
|
/**
|
|
2375
2519
|
* Get a Chat Model of copilot model and check it's token limitation, record the token usage
|
|
2376
2520
|
*/ class CreateModelClientCommand extends Command {
|
|
@@ -2381,10 +2525,26 @@ const COMMAND_METADATA = '__command__';
|
|
|
2381
2525
|
}
|
|
2382
2526
|
}
|
|
2383
2527
|
CreateModelClientCommand.type = '[AI Model] Create Model Client';
|
|
2384
|
-
Reflect.defineMetadata(COMMAND_METADATA, {
|
|
2528
|
+
Reflect.defineMetadata(COMMAND_METADATA$1, {
|
|
2385
2529
|
id: CreateModelClientCommand.type
|
|
2386
2530
|
}, CreateModelClientCommand);
|
|
2387
2531
|
|
|
2532
|
+
const SKILL_SOURCE_PROVIDER = 'SKILL_SOURCE_PROVIDER';
|
|
2533
|
+
const SkillSourceProviderStrategy = (provider)=>applyDecorators(SetMetadata(SKILL_SOURCE_PROVIDER, provider), SetMetadata(STRATEGY_META_KEY, SKILL_SOURCE_PROVIDER));
|
|
2534
|
+
|
|
2535
|
+
let SkillSourceProviderRegistry = class SkillSourceProviderRegistry extends BaseStrategyRegistry {
|
|
2536
|
+
constructor(discoveryService, reflector){
|
|
2537
|
+
super(SKILL_SOURCE_PROVIDER, discoveryService, reflector);
|
|
2538
|
+
}
|
|
2539
|
+
};
|
|
2540
|
+
SkillSourceProviderRegistry = __decorate([
|
|
2541
|
+
Injectable(),
|
|
2542
|
+
__metadata("design:paramtypes", [
|
|
2543
|
+
DiscoveryService,
|
|
2544
|
+
Reflector
|
|
2545
|
+
])
|
|
2546
|
+
], SkillSourceProviderRegistry);
|
|
2547
|
+
|
|
2388
2548
|
const AGENT_MIDDLEWARE_STRATEGY = 'AGENT_MIDDLEWARE_STRATEGY';
|
|
2389
2549
|
const AgentMiddlewareStrategy = (provider)=>applyDecorators(SetMetadata(AGENT_MIDDLEWARE_STRATEGY, provider), SetMetadata(STRATEGY_META_KEY, AGENT_MIDDLEWARE_STRATEGY));
|
|
2390
2550
|
|
|
@@ -2395,10 +2555,9 @@ let AgentMiddlewareRegistry = class AgentMiddlewareRegistry extends BaseStrategy
|
|
|
2395
2555
|
};
|
|
2396
2556
|
AgentMiddlewareRegistry = __decorate([
|
|
2397
2557
|
Injectable(),
|
|
2398
|
-
__metadata("design:type", Function),
|
|
2399
2558
|
__metadata("design:paramtypes", [
|
|
2400
|
-
|
|
2401
|
-
|
|
2559
|
+
DiscoveryService,
|
|
2560
|
+
Reflector
|
|
2402
2561
|
])
|
|
2403
2562
|
], AgentMiddlewareRegistry);
|
|
2404
2563
|
|
|
@@ -2410,15 +2569,7 @@ AgentMiddlewareRegistry = __decorate([
|
|
|
2410
2569
|
"end"
|
|
2411
2570
|
];
|
|
2412
2571
|
|
|
2413
|
-
|
|
2414
|
-
* Structured message types (suggested format):
|
|
2415
|
-
* - channel.{provider}.{action}.v{number}
|
|
2416
|
-
* - agent.{action}.v{number}
|
|
2417
|
-
* - system.{action}.v{number}
|
|
2418
|
-
* - plugin.{domain}.{action}.v{number}
|
|
2419
|
-
*
|
|
2420
|
-
* Note: At runtime, any string type is still allowed, facilitating dynamic extension by plugins.
|
|
2421
|
-
*/ const SEGMENT_PATTERN = /^[a-z][a-z0-9_-]*$/i;
|
|
2572
|
+
const SEGMENT_PATTERN = /^[a-z][a-z0-9_-]*$/i;
|
|
2422
2573
|
const VERSION_PATTERN = /^v[1-9][0-9]*$/;
|
|
2423
2574
|
function assertSegment(input, name) {
|
|
2424
2575
|
if (!SEGMENT_PATTERN.test(input)) {
|
|
@@ -2484,10 +2635,9 @@ let HandoffProcessorRegistry = class HandoffProcessorRegistry extends BaseStrate
|
|
|
2484
2635
|
};
|
|
2485
2636
|
HandoffProcessorRegistry = __decorate([
|
|
2486
2637
|
Injectable(),
|
|
2487
|
-
__metadata("design:type", Function),
|
|
2488
2638
|
__metadata("design:paramtypes", [
|
|
2489
|
-
|
|
2490
|
-
|
|
2639
|
+
DiscoveryService,
|
|
2640
|
+
Reflector
|
|
2491
2641
|
])
|
|
2492
2642
|
], HandoffProcessorRegistry);
|
|
2493
2643
|
|
|
@@ -2596,26 +2746,52 @@ HandoffProcessorRegistry = __decorate([
|
|
|
2596
2746
|
* ```
|
|
2597
2747
|
*/ const ChatChannel = (type)=>SetMetadata(CHAT_CHANNEL, type);
|
|
2598
2748
|
|
|
2599
|
-
|
|
2749
|
+
/**
|
|
2750
|
+
* Chat Channel Registry
|
|
2751
|
+
*
|
|
2752
|
+
* Manages all registered chat channel implementations.
|
|
2753
|
+
* Channels are automatically discovered and registered via @ChatChannel decorator.
|
|
2754
|
+
*
|
|
2755
|
+
* Supports:
|
|
2756
|
+
* - Organization-scoped channels
|
|
2757
|
+
* - Global channels (fallback)
|
|
2758
|
+
* - Plugin-based registration/removal
|
|
2759
|
+
* - Dynamic channel lookup
|
|
2760
|
+
*
|
|
2761
|
+
* @example
|
|
2762
|
+
* ```typescript
|
|
2763
|
+
* // Get channel by type
|
|
2764
|
+
* const channel = registry.get('lark')
|
|
2765
|
+
*
|
|
2766
|
+
* // List all available channels for an organization
|
|
2767
|
+
* const channels = registry.list(organizationId)
|
|
2768
|
+
*
|
|
2769
|
+
* // Send message using a channel
|
|
2770
|
+
* await channel.sendText(ctx, 'Hello!')
|
|
2771
|
+
* ```
|
|
2772
|
+
*/ let ChatChannelRegistry = class ChatChannelRegistry extends BaseStrategyRegistry {
|
|
2600
2773
|
constructor(discoveryService, reflector){
|
|
2601
2774
|
super(CHAT_CHANNEL, discoveryService, reflector);
|
|
2602
2775
|
}
|
|
2603
2776
|
};
|
|
2604
2777
|
ChatChannelRegistry = __decorate([
|
|
2605
2778
|
Injectable(),
|
|
2606
|
-
__metadata("design:type", Function),
|
|
2607
2779
|
__metadata("design:paramtypes", [
|
|
2608
|
-
|
|
2609
|
-
|
|
2780
|
+
DiscoveryService,
|
|
2781
|
+
Reflector
|
|
2610
2782
|
])
|
|
2611
2783
|
], ChatChannelRegistry);
|
|
2612
2784
|
|
|
2785
|
+
const COMMAND_METADATA = '__command__';
|
|
2613
2786
|
class CancelConversationCommand {
|
|
2614
2787
|
constructor(input){
|
|
2615
2788
|
this.input = input;
|
|
2616
2789
|
}
|
|
2617
2790
|
}
|
|
2618
2791
|
CancelConversationCommand.type = '[Chat Conversation] Cancel';
|
|
2792
|
+
Reflect.defineMetadata(COMMAND_METADATA, {
|
|
2793
|
+
id: CancelConversationCommand.type
|
|
2794
|
+
}, CancelConversationCommand);
|
|
2619
2795
|
|
|
2620
2796
|
const FILE_STORAGE_PROVIDER = 'FILE_STORAGE_PROVIDER';
|
|
2621
2797
|
const FileStorageProvider = (provider)=>applyDecorators(SetMetadata(FILE_STORAGE_PROVIDER, provider), SetMetadata(STRATEGY_META_KEY, FILE_STORAGE_PROVIDER));
|
|
@@ -2627,10 +2803,9 @@ let FileStorageProviderRegistry = class FileStorageProviderRegistry extends Base
|
|
|
2627
2803
|
};
|
|
2628
2804
|
FileStorageProviderRegistry = __decorate([
|
|
2629
2805
|
Injectable(),
|
|
2630
|
-
__metadata("design:type", Function),
|
|
2631
2806
|
__metadata("design:paramtypes", [
|
|
2632
|
-
|
|
2633
|
-
|
|
2807
|
+
DiscoveryService,
|
|
2808
|
+
Reflector
|
|
2634
2809
|
])
|
|
2635
2810
|
], FileStorageProviderRegistry);
|
|
2636
2811
|
|
|
@@ -2644,10 +2819,9 @@ let FileUploadTargetRegistry = class FileUploadTargetRegistry extends BaseStrate
|
|
|
2644
2819
|
};
|
|
2645
2820
|
FileUploadTargetRegistry = __decorate([
|
|
2646
2821
|
Injectable(),
|
|
2647
|
-
__metadata("design:type", Function),
|
|
2648
2822
|
__metadata("design:paramtypes", [
|
|
2649
|
-
|
|
2650
|
-
|
|
2823
|
+
DiscoveryService,
|
|
2824
|
+
Reflector
|
|
2651
2825
|
])
|
|
2652
2826
|
], FileUploadTargetRegistry);
|
|
2653
2827
|
|
|
@@ -2702,8 +2876,18 @@ function resolveSandboxExecutionOptions(options, defaults = DEFAULT_SANDBOX_SHEL
|
|
|
2702
2876
|
*
|
|
2703
2877
|
* @param backend - Backend instance to check
|
|
2704
2878
|
* @returns True if the backend implements SandboxBackendProtocol
|
|
2705
|
-
*/ function
|
|
2706
|
-
return typeof
|
|
2879
|
+
*/ function isObjectLike(value) {
|
|
2880
|
+
return typeof value === 'object' && value !== null;
|
|
2881
|
+
}
|
|
2882
|
+
function isSandboxBackend(backend) {
|
|
2883
|
+
return isObjectLike(backend) && typeof Reflect.get(backend, 'execute') === 'function' && typeof Reflect.get(backend, 'id') === 'string';
|
|
2884
|
+
}
|
|
2885
|
+
function resolveSandboxBackend(sandbox) {
|
|
2886
|
+
if (!isObjectLike(sandbox)) {
|
|
2887
|
+
return null;
|
|
2888
|
+
}
|
|
2889
|
+
const candidate = Reflect.has(sandbox, 'backend') ? Reflect.get(sandbox, 'backend') : sandbox;
|
|
2890
|
+
return isSandboxBackend(candidate) ? candidate : null;
|
|
2707
2891
|
}
|
|
2708
2892
|
|
|
2709
2893
|
const MAX_LINE_LENGTH = 500;
|
|
@@ -3321,6 +3505,13 @@ try {
|
|
|
3321
3505
|
*
|
|
3322
3506
|
* Requires Node.js 20+ on the sandbox host.
|
|
3323
3507
|
*/ class BaseSandbox {
|
|
3508
|
+
/**
|
|
3509
|
+
* Internal hook for file/search operations. Concrete backends can override
|
|
3510
|
+
* this to distinguish "background helper commands" from user-facing shell
|
|
3511
|
+
* execute calls.
|
|
3512
|
+
*/ executeOperation(command, options) {
|
|
3513
|
+
return this.execute(command, options);
|
|
3514
|
+
}
|
|
3324
3515
|
async streamExecute(command, onLine, options) {
|
|
3325
3516
|
const result = await this.execute(command, options);
|
|
3326
3517
|
if (result.output) {
|
|
@@ -3329,13 +3520,13 @@ try {
|
|
|
3329
3520
|
return result;
|
|
3330
3521
|
}
|
|
3331
3522
|
/**
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3523
|
+
* List files and directories in the specified directory (non-recursive).
|
|
3524
|
+
*
|
|
3525
|
+
* @param path - Absolute path to directory
|
|
3526
|
+
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
3527
|
+
*/ async lsInfo(path) {
|
|
3337
3528
|
const command = buildLsCommand(path);
|
|
3338
|
-
const result = await this.
|
|
3529
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3339
3530
|
if (result.exitCode !== 0) {
|
|
3340
3531
|
return [];
|
|
3341
3532
|
}
|
|
@@ -3357,14 +3548,14 @@ try {
|
|
|
3357
3548
|
return infos;
|
|
3358
3549
|
}
|
|
3359
3550
|
/**
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3551
|
+
* List directory contents recursively with depth control and pagination.
|
|
3552
|
+
*
|
|
3553
|
+
* @param dirPath - Absolute path to directory
|
|
3554
|
+
* @param offset - 1-indexed entry number to start from (default: 1)
|
|
3555
|
+
* @param limit - Maximum number of entries to return (default: 25)
|
|
3556
|
+
* @param depth - Maximum depth to traverse (default: 2)
|
|
3557
|
+
* @returns Human-readable directory tree with indentation
|
|
3558
|
+
*/ async listDir(dirPath, offset = 1, limit = 25, depth = 2) {
|
|
3368
3559
|
if (offset < 1) {
|
|
3369
3560
|
return 'Error: offset must be a 1-indexed entry number';
|
|
3370
3561
|
}
|
|
@@ -3375,34 +3566,34 @@ try {
|
|
|
3375
3566
|
return 'Error: depth must be greater than zero';
|
|
3376
3567
|
}
|
|
3377
3568
|
const command = buildListDirCommand(dirPath, offset, limit, depth);
|
|
3378
|
-
const result = await this.
|
|
3569
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3379
3570
|
if (result.exitCode !== 0) {
|
|
3380
3571
|
return result.output || `Error: Failed to list directory '${dirPath}'`;
|
|
3381
3572
|
}
|
|
3382
3573
|
return result.output;
|
|
3383
3574
|
}
|
|
3384
3575
|
/**
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3576
|
+
* Read file content with line numbers.
|
|
3577
|
+
*
|
|
3578
|
+
* @param filePath - Absolute file path
|
|
3579
|
+
* @param offset - Line offset to start reading from (1-indexed)
|
|
3580
|
+
* @param limit - Maximum number of lines to read
|
|
3581
|
+
* @param mode - Read mode: 'slice' (default) or 'indentation'
|
|
3582
|
+
* @param indentation - Configuration for indentation mode
|
|
3583
|
+
* @returns Formatted file content with line numbers, or error message
|
|
3584
|
+
*/ async read(filePath, offset = 1, limit = 2000, mode = 'slice', indentation) {
|
|
3394
3585
|
const command = mode === 'indentation' ? buildIndentationReadCommand(filePath, offset, limit, indentation != null ? indentation : {}) : buildSliceReadCommand(filePath, offset, limit);
|
|
3395
|
-
const result = await this.
|
|
3586
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3396
3587
|
if (result.exitCode !== 0) {
|
|
3397
3588
|
return result.output || `Error: File '${filePath}' not found`;
|
|
3398
3589
|
}
|
|
3399
3590
|
return result.output;
|
|
3400
3591
|
}
|
|
3401
3592
|
/**
|
|
3402
|
-
|
|
3403
|
-
|
|
3593
|
+
* Structured search results or error string for invalid input.
|
|
3594
|
+
*/ async grepRaw(pattern, path = '/', include = null) {
|
|
3404
3595
|
const command = buildGrepCommand(pattern, path, include);
|
|
3405
|
-
const result = await this.
|
|
3596
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS);
|
|
3406
3597
|
if (result.exitCode === 1) {
|
|
3407
3598
|
// Check if it's a regex error
|
|
3408
3599
|
if (result.output.includes('Invalid regex:')) {
|
|
@@ -3426,8 +3617,8 @@ try {
|
|
|
3426
3617
|
return matches;
|
|
3427
3618
|
}
|
|
3428
3619
|
/**
|
|
3429
|
-
|
|
3430
|
-
|
|
3620
|
+
* Search file contents for a regex pattern, returning human-readable output.
|
|
3621
|
+
*/ async grep(pattern, path = '/', include = null) {
|
|
3431
3622
|
const result = await this.grepRaw(pattern, path, include);
|
|
3432
3623
|
if (typeof result === 'string') {
|
|
3433
3624
|
return result;
|
|
@@ -3438,10 +3629,10 @@ try {
|
|
|
3438
3629
|
return formatGrepOutput(result);
|
|
3439
3630
|
}
|
|
3440
3631
|
/**
|
|
3441
|
-
|
|
3442
|
-
|
|
3632
|
+
* Structured glob matching returning FileInfo objects.
|
|
3633
|
+
*/ async globInfo(pattern, path = '/') {
|
|
3443
3634
|
const command = buildGlobCommand(path, pattern);
|
|
3444
|
-
const result = await this.
|
|
3635
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS);
|
|
3445
3636
|
const infos = [];
|
|
3446
3637
|
const lines = result.output.trim().split('\n').filter(Boolean);
|
|
3447
3638
|
for (const line of lines){
|
|
@@ -3460,8 +3651,8 @@ try {
|
|
|
3460
3651
|
return infos;
|
|
3461
3652
|
}
|
|
3462
3653
|
/**
|
|
3463
|
-
|
|
3464
|
-
|
|
3654
|
+
* Find files matching a glob pattern, returning human-readable output.
|
|
3655
|
+
*/ async glob(pattern, path = '/') {
|
|
3465
3656
|
const files = await this.globInfo(pattern, path);
|
|
3466
3657
|
if (files.length === 0) {
|
|
3467
3658
|
return 'No files found';
|
|
@@ -3469,10 +3660,10 @@ try {
|
|
|
3469
3660
|
return formatGlobOutput(files);
|
|
3470
3661
|
}
|
|
3471
3662
|
/**
|
|
3472
|
-
|
|
3473
|
-
|
|
3663
|
+
* Create a new file with content.
|
|
3664
|
+
*/ async write(filePath, content) {
|
|
3474
3665
|
const command = buildWriteCommand(filePath, content);
|
|
3475
|
-
const result = await this.
|
|
3666
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3476
3667
|
if (result.exitCode !== 0) {
|
|
3477
3668
|
const output = (result.output || '').trim();
|
|
3478
3669
|
if (output.includes(WRITE_EXISTS_OUTPUT)) {
|
|
@@ -3494,7 +3685,7 @@ try {
|
|
|
3494
3685
|
};
|
|
3495
3686
|
}
|
|
3496
3687
|
async writeViaUpload(filePath, content) {
|
|
3497
|
-
const existsCheck = await this.
|
|
3688
|
+
const existsCheck = await this.executeOperation(buildExistsCommand(filePath), DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3498
3689
|
if (existsCheck.exitCode === 0) {
|
|
3499
3690
|
return {
|
|
3500
3691
|
error: `Cannot write to ${filePath} because it already exists. Read and then make an edit, or write to a new path.`
|
|
@@ -3523,10 +3714,10 @@ try {
|
|
|
3523
3714
|
};
|
|
3524
3715
|
}
|
|
3525
3716
|
/**
|
|
3526
|
-
|
|
3527
|
-
|
|
3717
|
+
* Append content to a file. Creates the file if it doesn't exist.
|
|
3718
|
+
*/ async append(filePath, content) {
|
|
3528
3719
|
const command = buildAppendCommand(filePath, content);
|
|
3529
|
-
const result = await this.
|
|
3720
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3530
3721
|
if (result.exitCode !== 0) {
|
|
3531
3722
|
const output = (result.output || '').trim();
|
|
3532
3723
|
return {
|
|
@@ -3539,10 +3730,10 @@ try {
|
|
|
3539
3730
|
};
|
|
3540
3731
|
}
|
|
3541
3732
|
/**
|
|
3542
|
-
|
|
3543
|
-
|
|
3733
|
+
* Edit a file by replacing string occurrences.
|
|
3734
|
+
*/ async edit(filePath, oldString, newString, replaceAll = false) {
|
|
3544
3735
|
const command = buildEditCommand(filePath, oldString, newString, replaceAll);
|
|
3545
|
-
const result = await this.
|
|
3736
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3546
3737
|
switch(result.exitCode){
|
|
3547
3738
|
case 0:
|
|
3548
3739
|
{
|
|
@@ -3572,10 +3763,10 @@ try {
|
|
|
3572
3763
|
}
|
|
3573
3764
|
}
|
|
3574
3765
|
/**
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3766
|
+
* Perform multiple sequential edits on a single file.
|
|
3767
|
+
* All edits are applied sequentially, with each edit operating on the result of the previous edit.
|
|
3768
|
+
* All edits must succeed for the operation to succeed (atomic).
|
|
3769
|
+
*/ async multiEdit(filePath, edits) {
|
|
3579
3770
|
if (!edits || edits.length === 0) {
|
|
3580
3771
|
return {
|
|
3581
3772
|
error: 'No edits provided'
|
|
@@ -3615,11 +3806,48 @@ let SandboxProviderRegistry = class SandboxProviderRegistry extends BaseStrategy
|
|
|
3615
3806
|
};
|
|
3616
3807
|
SandboxProviderRegistry = __decorate([
|
|
3617
3808
|
Injectable(),
|
|
3618
|
-
__metadata("design:type", Function),
|
|
3619
3809
|
__metadata("design:paramtypes", [
|
|
3620
|
-
|
|
3621
|
-
|
|
3810
|
+
DiscoveryService,
|
|
3811
|
+
Reflector
|
|
3622
3812
|
])
|
|
3623
3813
|
], SandboxProviderRegistry);
|
|
3624
3814
|
|
|
3625
|
-
|
|
3815
|
+
const VIEW_EXTENSION_PROVIDER = 'VIEW_EXTENSION_PROVIDER';
|
|
3816
|
+
const ViewExtensionProvider = (providerKey)=>applyDecorators(SetMetadata(VIEW_EXTENSION_PROVIDER, providerKey), SetMetadata(STRATEGY_META_KEY, VIEW_EXTENSION_PROVIDER));
|
|
3817
|
+
|
|
3818
|
+
let ViewExtensionProviderRegistry = class ViewExtensionProviderRegistry extends BaseStrategyRegistry {
|
|
3819
|
+
listEntries(organizationId) {
|
|
3820
|
+
var _this_strategies_get;
|
|
3821
|
+
const orgKey = this.resolveOrganization(organizationId);
|
|
3822
|
+
const entries = new Map();
|
|
3823
|
+
var _this_strategies_get_entries;
|
|
3824
|
+
for (const [providerKey, provider] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(orgKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
3825
|
+
entries.set(providerKey, provider);
|
|
3826
|
+
}
|
|
3827
|
+
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
3828
|
+
var _this_strategies_get1;
|
|
3829
|
+
var _this_strategies_get_entries1;
|
|
3830
|
+
for (const [providerKey, provider] of (_this_strategies_get_entries1 = (_this_strategies_get1 = this.strategies.get(GLOBAL_ORGANIZATION_SCOPE)) == null ? void 0 : _this_strategies_get1.entries()) != null ? _this_strategies_get_entries1 : []){
|
|
3831
|
+
if (!entries.has(providerKey)) {
|
|
3832
|
+
entries.set(providerKey, provider);
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
return Array.from(entries.entries()).map(([providerKey, provider])=>({
|
|
3837
|
+
providerKey,
|
|
3838
|
+
provider
|
|
3839
|
+
}));
|
|
3840
|
+
}
|
|
3841
|
+
constructor(discoveryService, reflector){
|
|
3842
|
+
super(VIEW_EXTENSION_PROVIDER, discoveryService, reflector);
|
|
3843
|
+
}
|
|
3844
|
+
};
|
|
3845
|
+
ViewExtensionProviderRegistry = __decorate([
|
|
3846
|
+
Injectable(),
|
|
3847
|
+
__metadata("design:paramtypes", [
|
|
3848
|
+
DiscoveryService,
|
|
3849
|
+
Reflector
|
|
3850
|
+
])
|
|
3851
|
+
], ViewExtensionProviderRegistry);
|
|
3852
|
+
|
|
3853
|
+
export { AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, ANALYTICS_PERMISSION_SERVICE_TOKEN, AdapterDataSourceStrategy, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AiModelNotFoundException, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseSandbox, BaseStrategyRegistry, BaseTool, BaseToolset, BuiltinToolset, CHAT_CHANNEL, CHAT_CHANNEL_TEXT_LIMITS, CancelConversationCommand, ChatChannel, ChatChannelRegistry, ChatOAICompatReasoningModel, CommonParameterRules, CreateModelClientCommand, CredentialsValidateFailedError, DATASOURCE_STRATEGY, DBCreateTableMode, DBProtocolEnum, DBSyntaxEnum, DBTableAction, DBTableDataAction, DEFAULT_EXECUTION_CONFIG, DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC, DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS, DEFAULT_SANDBOX_SHELL_TIMEOUT_MS, DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DataSourceStrategy, DataSourceStrategyRegistry, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, FILE_STORAGE_PROVIDER, FILE_UPLOAD_TARGET_STRATEGY, FileStorageProvider, FileStorageProviderRegistry, FileUploadTargetRegistry, FileUploadTargetStrategy, GLOBAL_ORGANIZATION_SCOPE, HANDOFF_PERMISSION_SERVICE_TOKEN, HANDOFF_PROCESSOR_STRATEGY, HANDOFF_QUEUE_SERVICE_TOKEN, HandoffProcessorRegistry, HandoffProcessorStrategy, IMAGE_UNDERSTANDING_STRATEGY, INTEGRATION_PERMISSION_SERVICE_TOKEN, INTEGRATION_STRATEGY, ImageUnderstandingRegistry, ImageUnderstandingStrategy, IntegrationStrategyKey, IntegrationStrategyRegistry, JUMP_TO_TARGETS, JsonSchemaValidator, KNOWLEDGE_STRATEGY, KnowledgeStrategyKey, KnowledgeStrategyRegistry, LLMUsage, LargeLanguageModel, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_METADATA, PLUGIN_METADATA_KEY, PROVIDE_AI_MODEL_LLM, PROVIDE_AI_MODEL_MODERATION, PROVIDE_AI_MODEL_RERANK, PROVIDE_AI_MODEL_SPEECH2TEXT, PROVIDE_AI_MODEL_TEXT_EMBEDDING, PROVIDE_AI_MODEL_TTS, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SKILL_SOURCE_PROVIDER, STRATEGY_META_KEY, SandboxProviderRegistry, SandboxProviderStrategy, SkillSourceProviderRegistry, SkillSourceProviderStrategy, Speech2TextChatModel, SpeechToTextModel, StrategyBus, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextEmbeddingModelManager, TextSplitterRegistry, TextSplitterStrategy, TextToSpeechModel, ToolsetRegistry, ToolsetStrategy, USER_PERMISSION_SERVICE_TOKEN, VECTOR_STORE_STRATEGY, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, ViewExtensionProvider, ViewExtensionProviderRegistry, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WrapWorkflowNodeExecutionCommand, XpFileSystem, XpertServerPlugin, als, appendSandboxMessage, buildSandboxTimeoutMessage, calcTokenUsage, chunkText, countTokensSafe, createI18nInstance, createPluginLogger, defineAgentMessageType, defineChannelMessageType, downloadRemoteFile, formatSandboxTimeout, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, isRemoteFile, isSandboxBackend, isStructuredMessageType, loadYamlFile, mergeCredentials, mergeParentChildChunks, normalizeContextSize, resolveSandboxBackend, resolveSandboxExecutionOptions, runWithRequestContext, secondsToMilliseconds, sumTokenUsage };
|