@xpert-ai/plugin-sdk 3.12.2 → 3.14.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/CHANGELOG.md +24 -0
- package/index.cjs.js +88 -35
- package/index.esm.js +79 -36
- package/package.json +2 -1
- package/src/index.d.ts +1 -0
- package/src/lib/agent/handoff/agent-chat.contract.d.ts +4 -2
- package/src/lib/agent/middleware/types.d.ts +13 -4
- package/src/lib/managed-connection/index.d.ts +98 -0
- package/src/lib/strategy.d.ts +4 -2
- package/src/lib/toolset/strategy.interface.d.ts +2 -2
- package/src/lib/types.d.ts +8 -0
- package/src/lib/workflow/trigger/strategy.interface.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @xpert-ai/plugin-sdk
|
|
2
2
|
|
|
3
|
+
## 3.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6f679b8: fix plugin tenant scope & human chat files types
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [6f679b8]
|
|
12
|
+
- @xpert-ai/contracts@3.15.0
|
|
13
|
+
|
|
14
|
+
## 3.13.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 54cff15: tenants and managed connections
|
|
19
|
+
- 6978bfd: release plugin tenant scope
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [54cff15]
|
|
24
|
+
- Updated dependencies [6978bfd]
|
|
25
|
+
- @xpert-ai/contracts@3.14.0
|
|
26
|
+
|
|
3
27
|
## 3.12.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/index.cjs.js
CHANGED
|
@@ -91,7 +91,36 @@ var _axios__namespace = /*#__PURE__*/_interopNamespaceDefault(_axios);
|
|
|
91
91
|
const ORGANIZATION_METADATA_KEY = 'xpert:organizationId';
|
|
92
92
|
const PLUGIN_METADATA_KEY = 'xpert:pluginName';
|
|
93
93
|
const GLOBAL_ORGANIZATION_SCOPE = 'global';
|
|
94
|
+
const BUILTIN_GLOBAL_SCOPE = 'builtin:global';
|
|
95
|
+
const TENANT_GLOBAL_SCOPE_PREFIX = 'tenant:';
|
|
96
|
+
const TENANT_GLOBAL_SCOPE_SUFFIX = ':global';
|
|
94
97
|
const STRATEGY_META_KEY = 'XPERT_STRATEGY_META_KEY';
|
|
98
|
+
let defaultTenantId = null;
|
|
99
|
+
function normalizeOptionalString(value) {
|
|
100
|
+
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
|
|
101
|
+
}
|
|
102
|
+
function getTenantGlobalScopeKey(tenantId) {
|
|
103
|
+
return `${TENANT_GLOBAL_SCOPE_PREFIX}${tenantId}${TENANT_GLOBAL_SCOPE_SUFFIX}`;
|
|
104
|
+
}
|
|
105
|
+
function isTenantGlobalScopeKey(value) {
|
|
106
|
+
return typeof value === 'string' && value.startsWith(TENANT_GLOBAL_SCOPE_PREFIX) && value.endsWith(TENANT_GLOBAL_SCOPE_SUFFIX);
|
|
107
|
+
}
|
|
108
|
+
function setDefaultTenantId(tenantId) {
|
|
109
|
+
defaultTenantId = normalizeOptionalString(tenantId);
|
|
110
|
+
}
|
|
111
|
+
function getDefaultTenantId() {
|
|
112
|
+
return defaultTenantId;
|
|
113
|
+
}
|
|
114
|
+
function resolveTenantGlobalScopeKey(tenantId) {
|
|
115
|
+
const normalizedTenantId = normalizeOptionalString(tenantId);
|
|
116
|
+
if (!normalizedTenantId) {
|
|
117
|
+
return GLOBAL_ORGANIZATION_SCOPE;
|
|
118
|
+
}
|
|
119
|
+
if (defaultTenantId && normalizedTenantId !== defaultTenantId) {
|
|
120
|
+
return getTenantGlobalScopeKey(normalizedTenantId);
|
|
121
|
+
}
|
|
122
|
+
return GLOBAL_ORGANIZATION_SCOPE;
|
|
123
|
+
}
|
|
95
124
|
|
|
96
125
|
function _extends() {
|
|
97
126
|
_extends = Object.assign || function assign(target) {
|
|
@@ -485,14 +514,14 @@ class BaseStrategyRegistry {
|
|
|
485
514
|
if (type) {
|
|
486
515
|
var _instance_metatype;
|
|
487
516
|
const target = (_instance_metatype = instance.metatype) != null ? _instance_metatype : instance.constructor;
|
|
517
|
+
const pluginName = this.reflector.get(PLUGIN_METADATA_KEY, target);
|
|
488
518
|
var _this_reflector_get;
|
|
489
|
-
const organizationId = (_this_reflector_get = this.reflector.get(ORGANIZATION_METADATA_KEY, target)) != null ? _this_reflector_get : GLOBAL_ORGANIZATION_SCOPE;
|
|
519
|
+
const organizationId = (_this_reflector_get = this.reflector.get(ORGANIZATION_METADATA_KEY, target)) != null ? _this_reflector_get : pluginName ? GLOBAL_ORGANIZATION_SCOPE : BUILTIN_GLOBAL_SCOPE;
|
|
490
520
|
var _this_strategies_get;
|
|
491
521
|
const orgMap = (_this_strategies_get = this.strategies.get(organizationId)) != null ? _this_strategies_get : new Map();
|
|
492
522
|
orgMap.set(type, instance);
|
|
493
523
|
this.strategies.set(organizationId, orgMap);
|
|
494
|
-
|
|
495
|
-
this.logger.debug(`Registered strategy of type ${type} for organization ${organizationId} from plugin ${pluginName}`);
|
|
524
|
+
this.logger.debug(`Registered strategy of type ${type} for scope ${organizationId} from plugin ${pluginName}`);
|
|
496
525
|
if (pluginName) {
|
|
497
526
|
var _this_pluginStrategies_get;
|
|
498
527
|
const pluginStrategies = (_this_pluginStrategies_get = this.pluginStrategies.get(pluginName)) != null ? _this_pluginStrategies_get : new Set();
|
|
@@ -502,7 +531,7 @@ class BaseStrategyRegistry {
|
|
|
502
531
|
}
|
|
503
532
|
}
|
|
504
533
|
/**
|
|
505
|
-
* Remove all strategies registered by the given plugin for the given
|
|
534
|
+
* Remove all strategies registered by the given plugin for the given scope.
|
|
506
535
|
*/ remove(organizationId, pluginName) {
|
|
507
536
|
const strategies = this.pluginStrategies.get(pluginName);
|
|
508
537
|
const orgMap = this.strategies.get(organizationId);
|
|
@@ -511,10 +540,33 @@ class BaseStrategyRegistry {
|
|
|
511
540
|
}
|
|
512
541
|
}
|
|
513
542
|
/**
|
|
514
|
-
* Resolve
|
|
543
|
+
* Resolve the primary scope key, falling back to request context org or tenant-global scope.
|
|
515
544
|
*/ resolveOrganization(organizationId) {
|
|
516
|
-
var
|
|
517
|
-
|
|
545
|
+
var _RequestContext_getScope;
|
|
546
|
+
var _RequestContext_getScope_tenantId;
|
|
547
|
+
const tenantId = (_RequestContext_getScope_tenantId = (_RequestContext_getScope = RequestContext.getScope()) == null ? void 0 : _RequestContext_getScope.tenantId) != null ? _RequestContext_getScope_tenantId : RequestContext.currentTenantId();
|
|
548
|
+
const requested = organizationId != null ? organizationId : RequestContext.getOrganizationId();
|
|
549
|
+
return !requested || requested === GLOBAL_ORGANIZATION_SCOPE ? resolveTenantGlobalScopeKey(tenantId) : requested;
|
|
550
|
+
}
|
|
551
|
+
resolveGlobalFallbackOrganization() {
|
|
552
|
+
var _RequestContext_getScope;
|
|
553
|
+
var _RequestContext_getScope_tenantId;
|
|
554
|
+
const tenantId = (_RequestContext_getScope_tenantId = (_RequestContext_getScope = RequestContext.getScope()) == null ? void 0 : _RequestContext_getScope.tenantId) != null ? _RequestContext_getScope_tenantId : RequestContext.currentTenantId();
|
|
555
|
+
return resolveTenantGlobalScopeKey(tenantId);
|
|
556
|
+
}
|
|
557
|
+
resolveStrategyScopeKeys(organizationId) {
|
|
558
|
+
const orgKey = this.resolveOrganization(organizationId);
|
|
559
|
+
const globalKey = this.resolveGlobalFallbackOrganization();
|
|
560
|
+
const scopeKeys = [
|
|
561
|
+
orgKey
|
|
562
|
+
];
|
|
563
|
+
if (orgKey !== globalKey) {
|
|
564
|
+
scopeKeys.push(globalKey);
|
|
565
|
+
}
|
|
566
|
+
if (!scopeKeys.includes(BUILTIN_GLOBAL_SCOPE)) {
|
|
567
|
+
scopeKeys.push(BUILTIN_GLOBAL_SCOPE);
|
|
568
|
+
}
|
|
569
|
+
return scopeKeys;
|
|
518
570
|
}
|
|
519
571
|
/**
|
|
520
572
|
* Get strategy by type from the given organization including global strategies as fallback.
|
|
@@ -523,11 +575,11 @@ class BaseStrategyRegistry {
|
|
|
523
575
|
* @param organizationId
|
|
524
576
|
* @returns
|
|
525
577
|
*/ get(type, organizationId) {
|
|
526
|
-
var _this_strategies_get, _this_strategies_get1;
|
|
527
578
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
579
|
+
const strategy = this.resolveStrategyScopeKeys(organizationId).map((scopeKey)=>{
|
|
580
|
+
var _this_strategies_get;
|
|
581
|
+
return (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.get(type);
|
|
582
|
+
}).find((item)=>!!item);
|
|
531
583
|
if (!strategy) {
|
|
532
584
|
throw new Error(`No strategy found for type '${type}' for strategy '${this.strategyKey}'`);
|
|
533
585
|
}
|
|
@@ -539,18 +591,12 @@ class BaseStrategyRegistry {
|
|
|
539
591
|
* @param organizationId
|
|
540
592
|
* @returns
|
|
541
593
|
*/ list(organizationId) {
|
|
542
|
-
var _this_strategies_get;
|
|
543
594
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
544
|
-
const orgKey = this.resolveOrganization(organizationId);
|
|
545
595
|
const effective = new Map();
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
551
|
-
var _this_strategies_get1;
|
|
552
|
-
var _this_strategies_get_entries1;
|
|
553
|
-
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 : []){
|
|
596
|
+
for (const scopeKey of this.resolveStrategyScopeKeys(organizationId)){
|
|
597
|
+
var _this_strategies_get;
|
|
598
|
+
var _this_strategies_get_entries;
|
|
599
|
+
for (const [type, strategy] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
554
600
|
if (!effective.has(type)) {
|
|
555
601
|
effective.set(type, strategy);
|
|
556
602
|
}
|
|
@@ -560,7 +606,7 @@ class BaseStrategyRegistry {
|
|
|
560
606
|
}
|
|
561
607
|
constructor(strategyKey, discoveryService, reflector){
|
|
562
608
|
this.logger = new common.Logger(BaseStrategyRegistry.name);
|
|
563
|
-
// Map<
|
|
609
|
+
// Map<scopeKey, Map<type, strategy>>
|
|
564
610
|
this.strategies = new Map();
|
|
565
611
|
this.pluginStrategies = new Map();
|
|
566
612
|
this.strategyKey = strategyKey;
|
|
@@ -2756,9 +2802,9 @@ exports.AgentMiddlewareRegistry = __decorate([
|
|
|
2756
2802
|
/**
|
|
2757
2803
|
* jump targets (user facing)
|
|
2758
2804
|
*/ const JUMP_TO_TARGETS = [
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2805
|
+
'model',
|
|
2806
|
+
'tools',
|
|
2807
|
+
'end'
|
|
2762
2808
|
];
|
|
2763
2809
|
|
|
2764
2810
|
const AssistantTaskRuntimeCapability = createRuntimeCapability('platform.assistant_task', {
|
|
@@ -4066,22 +4112,19 @@ function resolveSandboxTerminalAdapter(sandbox) {
|
|
|
4066
4112
|
return isSandboxTerminalAdapter(candidate) ? candidate : null;
|
|
4067
4113
|
}
|
|
4068
4114
|
|
|
4115
|
+
const MANAGED_CONNECTION_REGISTRY_TOKEN = 'XPERT_MANAGED_CONNECTION_REGISTRY';
|
|
4116
|
+
const CONNECTION_COMMAND_ROUTER_TOKEN = 'XPERT_CONNECTION_COMMAND_ROUTER';
|
|
4117
|
+
|
|
4069
4118
|
const VIEW_EXTENSION_PROVIDER = 'VIEW_EXTENSION_PROVIDER';
|
|
4070
4119
|
const ViewExtensionProvider = (providerKey)=>common.applyDecorators(common.SetMetadata(VIEW_EXTENSION_PROVIDER, providerKey), common.SetMetadata(STRATEGY_META_KEY, VIEW_EXTENSION_PROVIDER));
|
|
4071
4120
|
|
|
4072
4121
|
exports.ViewExtensionProviderRegistry = class ViewExtensionProviderRegistry extends BaseStrategyRegistry {
|
|
4073
4122
|
listEntries(organizationId) {
|
|
4074
|
-
var _this_strategies_get;
|
|
4075
|
-
const orgKey = this.resolveOrganization(organizationId);
|
|
4076
4123
|
const entries = new Map();
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
4082
|
-
var _this_strategies_get1;
|
|
4083
|
-
var _this_strategies_get_entries1;
|
|
4084
|
-
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 : []){
|
|
4124
|
+
for (const scopeKey of this.resolveStrategyScopeKeys(organizationId)){
|
|
4125
|
+
var _this_strategies_get;
|
|
4126
|
+
var _this_strategies_get_entries;
|
|
4127
|
+
for (const [providerKey, provider] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
4085
4128
|
if (!entries.has(providerKey)) {
|
|
4086
4129
|
entries.set(providerKey, provider);
|
|
4087
4130
|
}
|
|
@@ -4540,6 +4583,7 @@ exports.AgentMiddlewareStrategy = AgentMiddlewareStrategy;
|
|
|
4540
4583
|
exports.AiModelNotFoundException = AiModelNotFoundException;
|
|
4541
4584
|
exports.AssistantTaskRuntimeCapability = AssistantTaskRuntimeCapability;
|
|
4542
4585
|
exports.BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN = BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN;
|
|
4586
|
+
exports.BUILTIN_GLOBAL_SCOPE = BUILTIN_GLOBAL_SCOPE;
|
|
4543
4587
|
exports.BaseHTTPQueryRunner = BaseHTTPQueryRunner;
|
|
4544
4588
|
exports.BaseQueryRunner = BaseQueryRunner;
|
|
4545
4589
|
exports.BaseSQLQueryRunner = BaseSQLQueryRunner;
|
|
@@ -4550,6 +4594,7 @@ exports.BaseToolset = BaseToolset;
|
|
|
4550
4594
|
exports.BuiltinToolset = BuiltinToolset;
|
|
4551
4595
|
exports.CHAT_CHANNEL = CHAT_CHANNEL;
|
|
4552
4596
|
exports.CHAT_CHANNEL_TEXT_LIMITS = CHAT_CHANNEL_TEXT_LIMITS;
|
|
4597
|
+
exports.CONNECTION_COMMAND_ROUTER_TOKEN = CONNECTION_COMMAND_ROUTER_TOKEN;
|
|
4553
4598
|
exports.CancelConversationCommand = CancelConversationCommand;
|
|
4554
4599
|
exports.ChatChannel = ChatChannel;
|
|
4555
4600
|
exports.ChatOAICompatReasoningModel = ChatOAICompatReasoningModel;
|
|
@@ -4598,6 +4643,7 @@ exports.KnowledgebaseDocumentsRuntimeCapability = KnowledgebaseDocumentsRuntimeC
|
|
|
4598
4643
|
exports.KnowledgebaseRuntimeCapability = KnowledgebaseRuntimeCapability;
|
|
4599
4644
|
exports.LLMUsage = LLMUsage;
|
|
4600
4645
|
exports.LargeLanguageModel = LargeLanguageModel;
|
|
4646
|
+
exports.MANAGED_CONNECTION_REGISTRY_TOKEN = MANAGED_CONNECTION_REGISTRY_TOKEN;
|
|
4601
4647
|
exports.ORGANIZATION_METADATA_KEY = ORGANIZATION_METADATA_KEY;
|
|
4602
4648
|
exports.OpenAICompatibleReranker = OpenAICompatibleReranker;
|
|
4603
4649
|
exports.PERMISSION_OPERATION_METADATA_KEY = PERMISSION_OPERATION_METADATA_KEY;
|
|
@@ -4631,6 +4677,8 @@ exports.SandboxProviderStrategy = SandboxProviderStrategy;
|
|
|
4631
4677
|
exports.SkillSourceProviderStrategy = SkillSourceProviderStrategy;
|
|
4632
4678
|
exports.Speech2TextChatModel = Speech2TextChatModel;
|
|
4633
4679
|
exports.SpeechToTextModel = SpeechToTextModel;
|
|
4680
|
+
exports.TENANT_GLOBAL_SCOPE_PREFIX = TENANT_GLOBAL_SCOPE_PREFIX;
|
|
4681
|
+
exports.TENANT_GLOBAL_SCOPE_SUFFIX = TENANT_GLOBAL_SCOPE_SUFFIX;
|
|
4634
4682
|
exports.TEXT_SPLITTER_STRATEGY = TEXT_SPLITTER_STRATEGY;
|
|
4635
4683
|
exports.TOOLSET_STRATEGY = TOOLSET_STRATEGY;
|
|
4636
4684
|
exports.TextEmbeddingModelManager = TextEmbeddingModelManager;
|
|
@@ -4665,6 +4713,7 @@ exports.defineAgentMessageType = defineAgentMessageType;
|
|
|
4665
4713
|
exports.defineChannelMessageType = defineChannelMessageType;
|
|
4666
4714
|
exports.downloadRemoteFile = downloadRemoteFile;
|
|
4667
4715
|
exports.formatSandboxTimeout = formatSandboxTimeout;
|
|
4716
|
+
exports.getDefaultTenantId = getDefaultTenantId;
|
|
4668
4717
|
exports.getErrorMessage = getErrorMessage;
|
|
4669
4718
|
exports.getModelContextSize = getModelContextSize;
|
|
4670
4719
|
exports.getPermissionOperationMetadata = getPermissionOperationMetadata;
|
|
@@ -4672,12 +4721,14 @@ exports.getPositionList = getPositionList;
|
|
|
4672
4721
|
exports.getPositionMap = getPositionMap;
|
|
4673
4722
|
exports.getRequestContext = getRequestContext;
|
|
4674
4723
|
exports.getRequiredPermissionOperation = getRequiredPermissionOperation;
|
|
4724
|
+
exports.getTenantGlobalScopeKey = getTenantGlobalScopeKey;
|
|
4675
4725
|
exports.isRemoteFile = isRemoteFile;
|
|
4676
4726
|
exports.isSandboxBackend = isSandboxBackend;
|
|
4677
4727
|
exports.isSandboxManagedServiceAdapter = isSandboxManagedServiceAdapter;
|
|
4678
4728
|
exports.isSandboxServiceProxyAdapter = isSandboxServiceProxyAdapter;
|
|
4679
4729
|
exports.isSandboxTerminalAdapter = isSandboxTerminalAdapter;
|
|
4680
4730
|
exports.isStructuredMessageType = isStructuredMessageType;
|
|
4731
|
+
exports.isTenantGlobalScopeKey = isTenantGlobalScopeKey;
|
|
4681
4732
|
exports.loadYamlFile = loadYamlFile;
|
|
4682
4733
|
exports.mergeCredentials = mergeCredentials;
|
|
4683
4734
|
exports.mergeParentChildChunks = mergeParentChildChunks;
|
|
@@ -4688,6 +4739,8 @@ exports.resolveSandboxExecutionOptions = resolveSandboxExecutionOptions;
|
|
|
4688
4739
|
exports.resolveSandboxManagedServiceAdapter = resolveSandboxManagedServiceAdapter;
|
|
4689
4740
|
exports.resolveSandboxServiceProxyAdapter = resolveSandboxServiceProxyAdapter;
|
|
4690
4741
|
exports.resolveSandboxTerminalAdapter = resolveSandboxTerminalAdapter;
|
|
4742
|
+
exports.resolveTenantGlobalScopeKey = resolveTenantGlobalScopeKey;
|
|
4691
4743
|
exports.runWithRequestContext = runWithRequestContext;
|
|
4692
4744
|
exports.secondsToMilliseconds = secondsToMilliseconds;
|
|
4745
|
+
exports.setDefaultTenantId = setDefaultTenantId;
|
|
4693
4746
|
exports.sumTokenUsage = sumTokenUsage;
|
package/index.esm.js
CHANGED
|
@@ -71,7 +71,36 @@ import { getModelContextSize as getModelContextSize$1 } from '@langchain/core/la
|
|
|
71
71
|
const ORGANIZATION_METADATA_KEY = 'xpert:organizationId';
|
|
72
72
|
const PLUGIN_METADATA_KEY = 'xpert:pluginName';
|
|
73
73
|
const GLOBAL_ORGANIZATION_SCOPE = 'global';
|
|
74
|
+
const BUILTIN_GLOBAL_SCOPE = 'builtin:global';
|
|
75
|
+
const TENANT_GLOBAL_SCOPE_PREFIX = 'tenant:';
|
|
76
|
+
const TENANT_GLOBAL_SCOPE_SUFFIX = ':global';
|
|
74
77
|
const STRATEGY_META_KEY = 'XPERT_STRATEGY_META_KEY';
|
|
78
|
+
let defaultTenantId = null;
|
|
79
|
+
function normalizeOptionalString(value) {
|
|
80
|
+
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : null;
|
|
81
|
+
}
|
|
82
|
+
function getTenantGlobalScopeKey(tenantId) {
|
|
83
|
+
return `${TENANT_GLOBAL_SCOPE_PREFIX}${tenantId}${TENANT_GLOBAL_SCOPE_SUFFIX}`;
|
|
84
|
+
}
|
|
85
|
+
function isTenantGlobalScopeKey(value) {
|
|
86
|
+
return typeof value === 'string' && value.startsWith(TENANT_GLOBAL_SCOPE_PREFIX) && value.endsWith(TENANT_GLOBAL_SCOPE_SUFFIX);
|
|
87
|
+
}
|
|
88
|
+
function setDefaultTenantId(tenantId) {
|
|
89
|
+
defaultTenantId = normalizeOptionalString(tenantId);
|
|
90
|
+
}
|
|
91
|
+
function getDefaultTenantId() {
|
|
92
|
+
return defaultTenantId;
|
|
93
|
+
}
|
|
94
|
+
function resolveTenantGlobalScopeKey(tenantId) {
|
|
95
|
+
const normalizedTenantId = normalizeOptionalString(tenantId);
|
|
96
|
+
if (!normalizedTenantId) {
|
|
97
|
+
return GLOBAL_ORGANIZATION_SCOPE;
|
|
98
|
+
}
|
|
99
|
+
if (defaultTenantId && normalizedTenantId !== defaultTenantId) {
|
|
100
|
+
return getTenantGlobalScopeKey(normalizedTenantId);
|
|
101
|
+
}
|
|
102
|
+
return GLOBAL_ORGANIZATION_SCOPE;
|
|
103
|
+
}
|
|
75
104
|
|
|
76
105
|
function _extends() {
|
|
77
106
|
_extends = Object.assign || function assign(target) {
|
|
@@ -465,14 +494,14 @@ class BaseStrategyRegistry {
|
|
|
465
494
|
if (type) {
|
|
466
495
|
var _instance_metatype;
|
|
467
496
|
const target = (_instance_metatype = instance.metatype) != null ? _instance_metatype : instance.constructor;
|
|
497
|
+
const pluginName = this.reflector.get(PLUGIN_METADATA_KEY, target);
|
|
468
498
|
var _this_reflector_get;
|
|
469
|
-
const organizationId = (_this_reflector_get = this.reflector.get(ORGANIZATION_METADATA_KEY, target)) != null ? _this_reflector_get : GLOBAL_ORGANIZATION_SCOPE;
|
|
499
|
+
const organizationId = (_this_reflector_get = this.reflector.get(ORGANIZATION_METADATA_KEY, target)) != null ? _this_reflector_get : pluginName ? GLOBAL_ORGANIZATION_SCOPE : BUILTIN_GLOBAL_SCOPE;
|
|
470
500
|
var _this_strategies_get;
|
|
471
501
|
const orgMap = (_this_strategies_get = this.strategies.get(organizationId)) != null ? _this_strategies_get : new Map();
|
|
472
502
|
orgMap.set(type, instance);
|
|
473
503
|
this.strategies.set(organizationId, orgMap);
|
|
474
|
-
|
|
475
|
-
this.logger.debug(`Registered strategy of type ${type} for organization ${organizationId} from plugin ${pluginName}`);
|
|
504
|
+
this.logger.debug(`Registered strategy of type ${type} for scope ${organizationId} from plugin ${pluginName}`);
|
|
476
505
|
if (pluginName) {
|
|
477
506
|
var _this_pluginStrategies_get;
|
|
478
507
|
const pluginStrategies = (_this_pluginStrategies_get = this.pluginStrategies.get(pluginName)) != null ? _this_pluginStrategies_get : new Set();
|
|
@@ -482,7 +511,7 @@ class BaseStrategyRegistry {
|
|
|
482
511
|
}
|
|
483
512
|
}
|
|
484
513
|
/**
|
|
485
|
-
* Remove all strategies registered by the given plugin for the given
|
|
514
|
+
* Remove all strategies registered by the given plugin for the given scope.
|
|
486
515
|
*/ remove(organizationId, pluginName) {
|
|
487
516
|
const strategies = this.pluginStrategies.get(pluginName);
|
|
488
517
|
const orgMap = this.strategies.get(organizationId);
|
|
@@ -491,10 +520,33 @@ class BaseStrategyRegistry {
|
|
|
491
520
|
}
|
|
492
521
|
}
|
|
493
522
|
/**
|
|
494
|
-
* Resolve
|
|
523
|
+
* Resolve the primary scope key, falling back to request context org or tenant-global scope.
|
|
495
524
|
*/ resolveOrganization(organizationId) {
|
|
496
|
-
var
|
|
497
|
-
|
|
525
|
+
var _RequestContext_getScope;
|
|
526
|
+
var _RequestContext_getScope_tenantId;
|
|
527
|
+
const tenantId = (_RequestContext_getScope_tenantId = (_RequestContext_getScope = RequestContext.getScope()) == null ? void 0 : _RequestContext_getScope.tenantId) != null ? _RequestContext_getScope_tenantId : RequestContext.currentTenantId();
|
|
528
|
+
const requested = organizationId != null ? organizationId : RequestContext.getOrganizationId();
|
|
529
|
+
return !requested || requested === GLOBAL_ORGANIZATION_SCOPE ? resolveTenantGlobalScopeKey(tenantId) : requested;
|
|
530
|
+
}
|
|
531
|
+
resolveGlobalFallbackOrganization() {
|
|
532
|
+
var _RequestContext_getScope;
|
|
533
|
+
var _RequestContext_getScope_tenantId;
|
|
534
|
+
const tenantId = (_RequestContext_getScope_tenantId = (_RequestContext_getScope = RequestContext.getScope()) == null ? void 0 : _RequestContext_getScope.tenantId) != null ? _RequestContext_getScope_tenantId : RequestContext.currentTenantId();
|
|
535
|
+
return resolveTenantGlobalScopeKey(tenantId);
|
|
536
|
+
}
|
|
537
|
+
resolveStrategyScopeKeys(organizationId) {
|
|
538
|
+
const orgKey = this.resolveOrganization(organizationId);
|
|
539
|
+
const globalKey = this.resolveGlobalFallbackOrganization();
|
|
540
|
+
const scopeKeys = [
|
|
541
|
+
orgKey
|
|
542
|
+
];
|
|
543
|
+
if (orgKey !== globalKey) {
|
|
544
|
+
scopeKeys.push(globalKey);
|
|
545
|
+
}
|
|
546
|
+
if (!scopeKeys.includes(BUILTIN_GLOBAL_SCOPE)) {
|
|
547
|
+
scopeKeys.push(BUILTIN_GLOBAL_SCOPE);
|
|
548
|
+
}
|
|
549
|
+
return scopeKeys;
|
|
498
550
|
}
|
|
499
551
|
/**
|
|
500
552
|
* Get strategy by type from the given organization including global strategies as fallback.
|
|
@@ -503,11 +555,11 @@ class BaseStrategyRegistry {
|
|
|
503
555
|
* @param organizationId
|
|
504
556
|
* @returns
|
|
505
557
|
*/ get(type, organizationId) {
|
|
506
|
-
var _this_strategies_get, _this_strategies_get1;
|
|
507
558
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
559
|
+
const strategy = this.resolveStrategyScopeKeys(organizationId).map((scopeKey)=>{
|
|
560
|
+
var _this_strategies_get;
|
|
561
|
+
return (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.get(type);
|
|
562
|
+
}).find((item)=>!!item);
|
|
511
563
|
if (!strategy) {
|
|
512
564
|
throw new Error(`No strategy found for type '${type}' for strategy '${this.strategyKey}'`);
|
|
513
565
|
}
|
|
@@ -519,18 +571,12 @@ class BaseStrategyRegistry {
|
|
|
519
571
|
* @param organizationId
|
|
520
572
|
* @returns
|
|
521
573
|
*/ list(organizationId) {
|
|
522
|
-
var _this_strategies_get;
|
|
523
574
|
organizationId != null ? organizationId : organizationId = RequestContext.getOrganizationId();
|
|
524
|
-
const orgKey = this.resolveOrganization(organizationId);
|
|
525
575
|
const effective = new Map();
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
531
|
-
var _this_strategies_get1;
|
|
532
|
-
var _this_strategies_get_entries1;
|
|
533
|
-
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 : []){
|
|
576
|
+
for (const scopeKey of this.resolveStrategyScopeKeys(organizationId)){
|
|
577
|
+
var _this_strategies_get;
|
|
578
|
+
var _this_strategies_get_entries;
|
|
579
|
+
for (const [type, strategy] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
534
580
|
if (!effective.has(type)) {
|
|
535
581
|
effective.set(type, strategy);
|
|
536
582
|
}
|
|
@@ -540,7 +586,7 @@ class BaseStrategyRegistry {
|
|
|
540
586
|
}
|
|
541
587
|
constructor(strategyKey, discoveryService, reflector){
|
|
542
588
|
this.logger = new Logger(BaseStrategyRegistry.name);
|
|
543
|
-
// Map<
|
|
589
|
+
// Map<scopeKey, Map<type, strategy>>
|
|
544
590
|
this.strategies = new Map();
|
|
545
591
|
this.pluginStrategies = new Map();
|
|
546
592
|
this.strategyKey = strategyKey;
|
|
@@ -2736,9 +2782,9 @@ AgentMiddlewareRegistry = __decorate([
|
|
|
2736
2782
|
/**
|
|
2737
2783
|
* jump targets (user facing)
|
|
2738
2784
|
*/ const JUMP_TO_TARGETS = [
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2785
|
+
'model',
|
|
2786
|
+
'tools',
|
|
2787
|
+
'end'
|
|
2742
2788
|
];
|
|
2743
2789
|
|
|
2744
2790
|
const AssistantTaskRuntimeCapability = createRuntimeCapability('platform.assistant_task', {
|
|
@@ -4046,22 +4092,19 @@ function resolveSandboxTerminalAdapter(sandbox) {
|
|
|
4046
4092
|
return isSandboxTerminalAdapter(candidate) ? candidate : null;
|
|
4047
4093
|
}
|
|
4048
4094
|
|
|
4095
|
+
const MANAGED_CONNECTION_REGISTRY_TOKEN = 'XPERT_MANAGED_CONNECTION_REGISTRY';
|
|
4096
|
+
const CONNECTION_COMMAND_ROUTER_TOKEN = 'XPERT_CONNECTION_COMMAND_ROUTER';
|
|
4097
|
+
|
|
4049
4098
|
const VIEW_EXTENSION_PROVIDER = 'VIEW_EXTENSION_PROVIDER';
|
|
4050
4099
|
const ViewExtensionProvider = (providerKey)=>applyDecorators(SetMetadata(VIEW_EXTENSION_PROVIDER, providerKey), SetMetadata(STRATEGY_META_KEY, VIEW_EXTENSION_PROVIDER));
|
|
4051
4100
|
|
|
4052
4101
|
let ViewExtensionProviderRegistry = class ViewExtensionProviderRegistry extends BaseStrategyRegistry {
|
|
4053
4102
|
listEntries(organizationId) {
|
|
4054
|
-
var _this_strategies_get;
|
|
4055
|
-
const orgKey = this.resolveOrganization(organizationId);
|
|
4056
4103
|
const entries = new Map();
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
if (orgKey !== GLOBAL_ORGANIZATION_SCOPE) {
|
|
4062
|
-
var _this_strategies_get1;
|
|
4063
|
-
var _this_strategies_get_entries1;
|
|
4064
|
-
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 : []){
|
|
4104
|
+
for (const scopeKey of this.resolveStrategyScopeKeys(organizationId)){
|
|
4105
|
+
var _this_strategies_get;
|
|
4106
|
+
var _this_strategies_get_entries;
|
|
4107
|
+
for (const [providerKey, provider] of (_this_strategies_get_entries = (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.entries()) != null ? _this_strategies_get_entries : []){
|
|
4065
4108
|
if (!entries.has(providerKey)) {
|
|
4066
4109
|
entries.set(providerKey, provider);
|
|
4067
4110
|
}
|
|
@@ -4500,4 +4543,4 @@ function escapeHtmlAttribute(value) {
|
|
|
4500
4543
|
|
|
4501
4544
|
const VIEW_EXTENSION_CACHE_SERVICE_TOKEN = 'XPERT_PLUGIN_VIEW_EXTENSION_CACHE_SERVICE';
|
|
4502
4545
|
|
|
4503
|
-
export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, ANALYTICS_PERMISSION_SERVICE_TOKEN, AdapterDataSourceStrategy, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AiModelNotFoundException, AssistantTaskRuntimeCapability, BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN, 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, DefaultRuntimeCapabilityRegistry as DefaultAgentMiddlewareRuntimeCapabilityRegistry, DefaultRuntimeCapabilityRegistry, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, FILE_STORAGE_PROVIDER, FILE_UPLOAD_TARGET_STRATEGY, FileRuntimeCapability, 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, KnowledgebaseDocumentsRuntimeCapability, KnowledgebaseRuntimeCapability, LLMUsage, LargeLanguageModel, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_METADATA, PLUGIN_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_SERVICE_TOKEN, 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, PluginWebhookAuth, PluginWebhookAuthGuard, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SKILL_SOURCE_PROVIDER, SPEECH_TO_TEXT_PERMISSION_SERVICE_TOKEN, SPEECH_TO_TEXT_SERVICE_TOKEN, SSOProviderRegistry, SSOProviderStrategyKey, SSO_BINDING_PERMISSION_SERVICE_TOKEN, SSO_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_CACHE_SERVICE_TOKEN, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, ViewExtensionProvider, ViewExtensionProviderRegistry, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WorkspaceFilesRuntimeCapability, WrapWorkflowNodeExecutionCommand, XPERT_RUNTIME_CAPABILITIES_TOKEN, XpFileSystem, XpertServerPlugin, als, appendSandboxMessage, buildSandboxTimeoutMessage, calcTokenUsage, chunkText, countTokensSafe, createI18nInstance, createPluginLogger, createRuntimeCapability, defineAgentMessageType, defineChannelMessageType, downloadRemoteFile, formatSandboxTimeout, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, isRemoteFile, isSandboxBackend, isSandboxManagedServiceAdapter, isSandboxServiceProxyAdapter, isSandboxTerminalAdapter, isStructuredMessageType, loadYamlFile, mergeCredentials, mergeParentChildChunks, normalizeContextSize, renderRemoteReactIframeHtml, resolveSandboxBackend, resolveSandboxExecutionOptions, resolveSandboxManagedServiceAdapter, resolveSandboxServiceProxyAdapter, resolveSandboxTerminalAdapter, runWithRequestContext, secondsToMilliseconds, sumTokenUsage };
|
|
4546
|
+
export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, ANALYTICS_PERMISSION_SERVICE_TOKEN, AdapterDataSourceStrategy, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AiModelNotFoundException, AssistantTaskRuntimeCapability, BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN, BUILTIN_GLOBAL_SCOPE, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseSandbox, BaseStrategyRegistry, BaseTool, BaseToolset, BuiltinToolset, CHAT_CHANNEL, CHAT_CHANNEL_TEXT_LIMITS, CONNECTION_COMMAND_ROUTER_TOKEN, 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, DefaultRuntimeCapabilityRegistry as DefaultAgentMiddlewareRuntimeCapabilityRegistry, DefaultRuntimeCapabilityRegistry, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, FILE_STORAGE_PROVIDER, FILE_UPLOAD_TARGET_STRATEGY, FileRuntimeCapability, 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, KnowledgebaseDocumentsRuntimeCapability, KnowledgebaseRuntimeCapability, LLMUsage, LargeLanguageModel, MANAGED_CONNECTION_REGISTRY_TOKEN, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_METADATA, PLUGIN_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_METADATA_KEY, PLUGIN_WEBHOOK_AUTH_SERVICE_TOKEN, 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, PluginWebhookAuth, PluginWebhookAuthGuard, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SKILL_SOURCE_PROVIDER, SPEECH_TO_TEXT_PERMISSION_SERVICE_TOKEN, SPEECH_TO_TEXT_SERVICE_TOKEN, SSOProviderRegistry, SSOProviderStrategyKey, SSO_BINDING_PERMISSION_SERVICE_TOKEN, SSO_PROVIDER, STRATEGY_META_KEY, SandboxProviderRegistry, SandboxProviderStrategy, SkillSourceProviderRegistry, SkillSourceProviderStrategy, Speech2TextChatModel, SpeechToTextModel, StrategyBus, TENANT_GLOBAL_SCOPE_PREFIX, TENANT_GLOBAL_SCOPE_SUFFIX, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextEmbeddingModelManager, TextSplitterRegistry, TextSplitterStrategy, TextToSpeechModel, ToolsetRegistry, ToolsetStrategy, USER_PERMISSION_SERVICE_TOKEN, VECTOR_STORE_STRATEGY, VIEW_EXTENSION_CACHE_SERVICE_TOKEN, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, ViewExtensionProvider, ViewExtensionProviderRegistry, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WorkspaceFilesRuntimeCapability, WrapWorkflowNodeExecutionCommand, XPERT_RUNTIME_CAPABILITIES_TOKEN, XpFileSystem, XpertServerPlugin, als, appendSandboxMessage, buildSandboxTimeoutMessage, calcTokenUsage, chunkText, countTokensSafe, createI18nInstance, createPluginLogger, createRuntimeCapability, defineAgentMessageType, defineChannelMessageType, downloadRemoteFile, formatSandboxTimeout, getDefaultTenantId, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, getTenantGlobalScopeKey, isRemoteFile, isSandboxBackend, isSandboxManagedServiceAdapter, isSandboxServiceProxyAdapter, isSandboxTerminalAdapter, isStructuredMessageType, isTenantGlobalScopeKey, loadYamlFile, mergeCredentials, mergeParentChildChunks, normalizeContextSize, renderRemoteReactIframeHtml, resolveSandboxBackend, resolveSandboxExecutionOptions, resolveSandboxManagedServiceAdapter, resolveSandboxServiceProxyAdapter, resolveSandboxTerminalAdapter, resolveTenantGlobalScopeKey, runWithRequestContext, secondsToMilliseconds, setDefaultTenantId, sumTokenUsage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"directory": "dist"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@langchain/openai": "0.6.9",
|
|
19
20
|
"@xpert-ai/contracts": "workspace:*",
|
|
20
21
|
"js-tiktoken": "^1.0.21"
|
|
21
22
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TChatOptions, TChatRequest } from '@xpert-ai/contracts';
|
|
1
|
+
import { TChatOptions, TChatRequest, TChatRuntimePrincipal, TChatSourceAuditOptions } from '@xpert-ai/contracts';
|
|
2
2
|
export declare const AGENT_CHAT_DISPATCH_MESSAGE_TYPE: import("./message-type").StructuredHandoffMessageType;
|
|
3
3
|
export interface AgentChatHandoffMessageCallbackTarget {
|
|
4
4
|
transport?: 'handoff-message';
|
|
@@ -11,13 +11,15 @@ export interface AgentChatRedisPubSubCallbackTarget {
|
|
|
11
11
|
context?: Record<string, unknown>;
|
|
12
12
|
}
|
|
13
13
|
export type AgentChatCallbackTarget = AgentChatHandoffMessageCallbackTarget | AgentChatRedisPubSubCallbackTarget;
|
|
14
|
+
export type AgentChatRuntimePrincipal = TChatRuntimePrincipal;
|
|
14
15
|
export interface AgentChatDispatchPayload extends Record<string, unknown> {
|
|
15
16
|
request: TChatRequest;
|
|
16
|
-
options: TChatOptions & {
|
|
17
|
+
options: TChatOptions & TChatSourceAuditOptions & {
|
|
17
18
|
xpertId?: string;
|
|
18
19
|
isDraft?: boolean;
|
|
19
20
|
from?: string;
|
|
20
21
|
fromEndUserId?: string;
|
|
22
|
+
runtimePrincipal?: AgentChatRuntimePrincipal;
|
|
21
23
|
execution?: {
|
|
22
24
|
id: string;
|
|
23
25
|
};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { LanguageModelLike } from '@langchain/core/language_models/base';
|
|
2
2
|
import { AIMessage, BaseMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
3
|
import { DynamicStructuredTool, DynamicTool, StructuredToolInterface } from '@langchain/core/tools';
|
|
4
|
-
import type { ToolCall, ToolMessage } from
|
|
4
|
+
import type { ToolCall, ToolMessage } from '@langchain/core/messages/tool';
|
|
5
5
|
import { InferInteropZodOutput, InteropZodObject } from '@langchain/core/utils/types';
|
|
6
6
|
import { RunnableToolLike } from '@langchain/core/runnables';
|
|
7
7
|
import { Command } from '@langchain/langgraph';
|
|
8
|
+
import type { JsonSchemaObjectType } from '@xpert-ai/contracts';
|
|
8
9
|
import { AgentBuiltInState, Runtime } from './runtime';
|
|
9
10
|
import { PromiseOrValue } from '../../types';
|
|
10
11
|
export type ServerTool = Record<string, unknown>;
|
|
11
12
|
export type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
|
|
12
|
-
export type NormalizedSchemaInput<TSchema extends InteropZodObject | undefined | never = any> = [TSchema] extends [
|
|
13
|
+
export type NormalizedSchemaInput<TSchema extends InteropZodObject | undefined | never = any> = [TSchema] extends [
|
|
14
|
+
never
|
|
15
|
+
] ? AgentBuiltInState : TSchema extends InteropZodObject ? InferInteropZodOutput<TSchema> & AgentBuiltInState : TSchema extends Record<string, unknown> ? TSchema & AgentBuiltInState : AgentBuiltInState;
|
|
13
16
|
type NormalizeContextSchema<TContextSchema extends InteropZodObject | undefined = undefined> = TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : never;
|
|
14
17
|
/**
|
|
15
18
|
* jump targets (user facing)
|
|
@@ -120,8 +123,8 @@ export interface ModelRequest<TState extends Record<string, unknown> = Record<st
|
|
|
120
123
|
* - `"required"`: means the model must call one or more tools.
|
|
121
124
|
* - `{ type: "function", function: { name: string } }`: The model will use the specified function.
|
|
122
125
|
*/
|
|
123
|
-
toolChoice?:
|
|
124
|
-
type:
|
|
126
|
+
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
127
|
+
type: 'function';
|
|
125
128
|
function: {
|
|
126
129
|
name: string;
|
|
127
130
|
};
|
|
@@ -207,6 +210,12 @@ export interface AgentMiddleware<TSchema extends InteropZodObject | undefined =
|
|
|
207
210
|
* - Undefined
|
|
208
211
|
*/
|
|
209
212
|
stateSchema?: TSchema;
|
|
213
|
+
/**
|
|
214
|
+
* Optional JSON schema used by host form renderers for middleware state.
|
|
215
|
+
* Keep runtime validation and state typing in `stateSchema`; use this field
|
|
216
|
+
* only for form/UI metadata such as i18n labels and x-ui extensions.
|
|
217
|
+
*/
|
|
218
|
+
stateFormSchema?: JsonSchemaObjectType;
|
|
210
219
|
/**
|
|
211
220
|
* The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:
|
|
212
221
|
* - A Zod object
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export declare const MANAGED_CONNECTION_REGISTRY_TOKEN = "XPERT_MANAGED_CONNECTION_REGISTRY";
|
|
2
|
+
export declare const CONNECTION_COMMAND_ROUTER_TOKEN = "XPERT_CONNECTION_COMMAND_ROUTER";
|
|
3
|
+
export type ManagedConnectionTransportType = 'websocket' | 'socket_io' | 'sse' | 'tcp_tunnel' | 'worker' | 'custom';
|
|
4
|
+
export type ManagedConnectionStatus = 'connected' | 'disconnected' | 'stale' | 'error';
|
|
5
|
+
export type ManagedConnectionDirection = 'inbound' | 'outbound' | 'internal';
|
|
6
|
+
export type ManagedConnectionRecord = {
|
|
7
|
+
id?: string;
|
|
8
|
+
pluginName: string;
|
|
9
|
+
connectionType: string;
|
|
10
|
+
connectionKey: string;
|
|
11
|
+
transportType: ManagedConnectionTransportType;
|
|
12
|
+
direction: ManagedConnectionDirection;
|
|
13
|
+
ownerInstanceId: string;
|
|
14
|
+
status: ManagedConnectionStatus;
|
|
15
|
+
connectedAt?: Date | string | null;
|
|
16
|
+
lastSeenAt?: Date | string | null;
|
|
17
|
+
leaseExpiresAt?: Date | string | null;
|
|
18
|
+
disconnectedAt?: Date | string | null;
|
|
19
|
+
remoteAddress?: string | null;
|
|
20
|
+
metadata?: Record<string, unknown> | null;
|
|
21
|
+
lastError?: string | null;
|
|
22
|
+
tenantId?: string | null;
|
|
23
|
+
organizationId?: string | null;
|
|
24
|
+
};
|
|
25
|
+
export type RegisterManagedConnectionInput = {
|
|
26
|
+
pluginName: string;
|
|
27
|
+
connectionType: string;
|
|
28
|
+
connectionKey: string;
|
|
29
|
+
transportType: ManagedConnectionTransportType;
|
|
30
|
+
direction?: ManagedConnectionDirection;
|
|
31
|
+
tenantId?: string | null;
|
|
32
|
+
organizationId?: string | null;
|
|
33
|
+
remoteAddress?: string | null;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
leaseTtlMs?: number;
|
|
36
|
+
};
|
|
37
|
+
export type ManagedConnectionKeyInput = {
|
|
38
|
+
pluginName?: string;
|
|
39
|
+
connectionType: string;
|
|
40
|
+
connectionKey: string;
|
|
41
|
+
tenantId?: string | null;
|
|
42
|
+
organizationId?: string | null;
|
|
43
|
+
};
|
|
44
|
+
export type ManagedConnectionHeartbeatInput = ManagedConnectionKeyInput & {
|
|
45
|
+
remoteAddress?: string | null;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
leaseTtlMs?: number;
|
|
48
|
+
};
|
|
49
|
+
export type ManagedConnectionMetadataInput = ManagedConnectionKeyInput & {
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
merge?: boolean;
|
|
52
|
+
leaseTtlMs?: number;
|
|
53
|
+
};
|
|
54
|
+
export type ManagedConnectionListQuery = {
|
|
55
|
+
pluginName?: string;
|
|
56
|
+
connectionType?: string;
|
|
57
|
+
connectionKey?: string;
|
|
58
|
+
transportType?: ManagedConnectionTransportType;
|
|
59
|
+
direction?: ManagedConnectionDirection;
|
|
60
|
+
ownerInstanceId?: string;
|
|
61
|
+
status?: ManagedConnectionStatus | ManagedConnectionStatus[];
|
|
62
|
+
activeOnly?: boolean;
|
|
63
|
+
tenantId?: string | null;
|
|
64
|
+
organizationId?: string | null;
|
|
65
|
+
limit?: number;
|
|
66
|
+
offset?: number;
|
|
67
|
+
};
|
|
68
|
+
export type ManagedConnectionCommandRequest<TPayload = unknown> = {
|
|
69
|
+
requestId: string;
|
|
70
|
+
connectionType: string;
|
|
71
|
+
connectionKey: string;
|
|
72
|
+
command: string;
|
|
73
|
+
payload?: TPayload;
|
|
74
|
+
};
|
|
75
|
+
export type ManagedConnectionCommandHandler<TPayload = unknown, TResult = unknown> = (request: ManagedConnectionCommandRequest<TPayload>) => Promise<TResult> | TResult;
|
|
76
|
+
export type ManagedConnectionCommandResult<TResult = unknown> = {
|
|
77
|
+
ok: boolean;
|
|
78
|
+
result?: TResult;
|
|
79
|
+
error?: string;
|
|
80
|
+
};
|
|
81
|
+
export type ConnectionCommandInvokeOptions = {
|
|
82
|
+
pluginName?: string;
|
|
83
|
+
tenantId?: string | null;
|
|
84
|
+
organizationId?: string | null;
|
|
85
|
+
timeoutMs?: number;
|
|
86
|
+
};
|
|
87
|
+
export interface ManagedConnectionRegistry {
|
|
88
|
+
register(input: RegisterManagedConnectionInput): Promise<ManagedConnectionRecord>;
|
|
89
|
+
heartbeat(input: ManagedConnectionHeartbeatInput): Promise<void>;
|
|
90
|
+
syncMetadata(input: ManagedConnectionMetadataInput): Promise<void>;
|
|
91
|
+
markDisconnected(input: ManagedConnectionKeyInput, reason?: string): Promise<void>;
|
|
92
|
+
list(query: ManagedConnectionListQuery): Promise<ManagedConnectionRecord[]>;
|
|
93
|
+
getOwner(input: ManagedConnectionKeyInput): Promise<string | null>;
|
|
94
|
+
}
|
|
95
|
+
export interface ConnectionCommandRouter {
|
|
96
|
+
registerHandler(connectionType: string, handler: ManagedConnectionCommandHandler): void;
|
|
97
|
+
invokeOwner(connectionType: string, connectionKey: string, command: string, payload?: unknown, options?: ConnectionCommandInvokeOptions): Promise<unknown>;
|
|
98
|
+
}
|
package/src/lib/strategy.d.ts
CHANGED
|
@@ -13,13 +13,15 @@ export declare class BaseStrategyRegistry<S> implements OnModuleInit {
|
|
|
13
13
|
onModuleInit(): void;
|
|
14
14
|
upsert(instance: any): void;
|
|
15
15
|
/**
|
|
16
|
-
* Remove all strategies registered by the given plugin for the given
|
|
16
|
+
* Remove all strategies registered by the given plugin for the given scope.
|
|
17
17
|
*/
|
|
18
18
|
remove(organizationId: string, pluginName: string): void;
|
|
19
19
|
/**
|
|
20
|
-
* Resolve
|
|
20
|
+
* Resolve the primary scope key, falling back to request context org or tenant-global scope.
|
|
21
21
|
*/
|
|
22
22
|
protected resolveOrganization(organizationId?: string): string;
|
|
23
|
+
protected resolveGlobalFallbackOrganization(): string;
|
|
24
|
+
protected resolveStrategyScopeKeys(organizationId?: string): string[];
|
|
23
25
|
/**
|
|
24
26
|
* Get strategy by type from the given organization including global strategies as fallback.
|
|
25
27
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
2
|
import { I18nObject, IconDefinition } from '@xpert-ai/contracts';
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
|
-
import { BuiltinToolset } from './builtin';
|
|
4
|
+
import { BuiltinToolset, TBuiltinToolsetParams } from './builtin';
|
|
5
5
|
export interface IToolsetStrategy<TConfig = any> {
|
|
6
6
|
/**
|
|
7
7
|
* Metadata about this toolset
|
|
@@ -19,6 +19,6 @@ export interface IToolsetStrategy<TConfig = any> {
|
|
|
19
19
|
* Validate the configuration
|
|
20
20
|
*/
|
|
21
21
|
validateConfig(config: TConfig): Promise<void>;
|
|
22
|
-
create(config: TConfig): Promise<BuiltinToolset>;
|
|
22
|
+
create(config: TConfig, params?: TBuiltinToolsetParams): Promise<BuiltinToolset>;
|
|
23
23
|
createTools(): DynamicStructuredTool<ZodSchema>[];
|
|
24
24
|
}
|
package/src/lib/types.d.ts
CHANGED
|
@@ -6,7 +6,15 @@ import type { Permissions } from './core/permissions';
|
|
|
6
6
|
export declare const ORGANIZATION_METADATA_KEY = "xpert:organizationId";
|
|
7
7
|
export declare const PLUGIN_METADATA_KEY = "xpert:pluginName";
|
|
8
8
|
export declare const GLOBAL_ORGANIZATION_SCOPE = "global";
|
|
9
|
+
export declare const BUILTIN_GLOBAL_SCOPE = "builtin:global";
|
|
10
|
+
export declare const TENANT_GLOBAL_SCOPE_PREFIX = "tenant:";
|
|
11
|
+
export declare const TENANT_GLOBAL_SCOPE_SUFFIX = ":global";
|
|
9
12
|
export declare const STRATEGY_META_KEY = "XPERT_STRATEGY_META_KEY";
|
|
13
|
+
export declare function getTenantGlobalScopeKey(tenantId: string): string;
|
|
14
|
+
export declare function isTenantGlobalScopeKey(value?: string | null): boolean;
|
|
15
|
+
export declare function setDefaultTenantId(tenantId?: string | null): void;
|
|
16
|
+
export declare function getDefaultTenantId(): string;
|
|
17
|
+
export declare function resolveTenantGlobalScopeKey(tenantId?: string | null): string;
|
|
10
18
|
export interface PluginLifecycle {
|
|
11
19
|
/** Called after module registration but before application startup */
|
|
12
20
|
onInit?(ctx: PluginContext): Promise<void> | void;
|
|
@@ -27,7 +27,7 @@ export interface IWorkflowTriggerStrategy<T> {
|
|
|
27
27
|
* @param payload
|
|
28
28
|
* @param callback
|
|
29
29
|
*/
|
|
30
|
-
publish(payload: TWorkflowTriggerParams<T>, callback: (payload: any) => void): Promise<any> | void;
|
|
30
|
+
publish(payload: TWorkflowTriggerParams<T>, callback: (payload: any) => Promise<void> | void): Promise<any> | void;
|
|
31
31
|
/**
|
|
32
32
|
* Stop the trigger
|
|
33
33
|
*/
|