@xpert-ai/plugin-sdk 3.18.1 → 3.18.2
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 +8 -0
- package/README.md +51 -0
- package/index.cjs.js +680 -50
- package/index.esm.js +675 -54
- package/model-provider.esm.js +1 -1
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/lib/ai-model/entities/defaults.d.ts +2 -2
- package/src/lib/core/strategy-bus.d.ts +2 -1
- package/src/lib/strategy.d.ts +19 -0
- package/src/lib/tool-provider/adapters.d.ts +27 -0
- package/src/lib/tool-provider/coordinator.d.ts +20 -0
- package/src/lib/tool-provider/decorators.d.ts +8 -0
- package/src/lib/tool-provider/descriptor.d.ts +3 -0
- package/src/lib/tool-provider/index.d.ts +6 -0
- package/src/lib/tool-provider/registry.d.ts +10 -0
- package/src/lib/tool-provider/types.d.ts +98 -0
package/model-provider.esm.js
CHANGED
|
@@ -364,4 +364,4 @@ function normalizeWorkspaceScope(scope) {
|
|
|
364
364
|
} : {});
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
export { ActorTokenRuntimeCapability as A,
|
|
367
|
+
export { ActorTokenRuntimeCapability as A, BuiltinToolset as B, DefaultRuntimeCapabilityRegistry as D, KnowledgeDocumentVisualAssetsRuntimeCapability as K, ModelProviderBuiltinToolset as M, ProjectProvisioningRuntimeCapability as P, SANDBOX_JOB_ERROR_CODES as S, WORKSPACE_FILES_SOURCE as W, XPERT_RUNTIME_CAPABILITIES_TOKEN as X, ArtifactsRuntimeCapability as a, BaseTool as b, createRuntimeCapability as c, BaseToolset as d, KnowledgebaseDocumentsRuntimeCapability as e, KnowledgebaseProvisioningRuntimeCapability as f, KnowledgebaseRuntimeCapability as g, SANDBOX_JOB_PROGRESS_PREFIX as h, SandboxJobRuntimeError as i, SandboxJobsRuntimeCapability as j, WorkspaceFilesRuntimeCapability as k, isSandboxJobRuntimeError as l };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.18.
|
|
3
|
+
"version": "3.18.2",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@langchain/openai": "0.6.9",
|
|
20
|
-
"@xpert-ai/contracts": "3.18.
|
|
20
|
+
"@xpert-ai/contracts": "3.18.1",
|
|
21
21
|
"express": "^4.22.1",
|
|
22
22
|
"js-tiktoken": "^1.0.21"
|
|
23
23
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ParameterRule } from
|
|
2
|
-
import { DefaultParameterName } from
|
|
1
|
+
import { ParameterRule } from '@xpert-ai/contracts';
|
|
2
|
+
import { DefaultParameterName } from './model_entities';
|
|
3
3
|
export declare const PARAMETER_RULE_TEMPLATE: Record<DefaultParameterName, ParameterRule>;
|
|
@@ -8,10 +8,11 @@ export type StrategyBusEvent<S = any> = {
|
|
|
8
8
|
strategyType?: string;
|
|
9
9
|
pluginName: string;
|
|
10
10
|
orgId: string;
|
|
11
|
+
cause?: 'refresh' | 'uninstall';
|
|
11
12
|
};
|
|
12
13
|
export declare class StrategyBus {
|
|
13
14
|
private readonly subject;
|
|
14
15
|
readonly events$: import("rxjs").Observable<StrategyBusEvent<any>>;
|
|
15
16
|
upsert<S>(strategyType: string, entry: StrategyEntry<S>): void;
|
|
16
|
-
remove(orgId: string, pluginName: string): void;
|
|
17
|
+
remove(orgId: string, pluginName: string, cause?: 'refresh' | 'uninstall'): void;
|
|
17
18
|
}
|
package/src/lib/strategy.d.ts
CHANGED
|
@@ -18,9 +18,16 @@ export declare class BaseStrategyRegistry<S> implements OnModuleInit {
|
|
|
18
18
|
protected readonly bus: StrategyBus;
|
|
19
19
|
protected strategies: Map<string, Map<string, S>>;
|
|
20
20
|
protected pluginStrategies: Map<string, Set<string>>;
|
|
21
|
+
private readonly explicitSources;
|
|
21
22
|
constructor(strategyKey: string, discoveryService: DiscoveryService, reflector: Reflector);
|
|
22
23
|
onModuleInit(): void;
|
|
23
24
|
upsert(instance: unknown): void;
|
|
25
|
+
/** Registers a host-generated adapter without mutating shared class metadata. */
|
|
26
|
+
register(type: string, instance: S, source: StrategySource): S;
|
|
27
|
+
/** Preflights adapter batches so a provider is expanded atomically across registries. */
|
|
28
|
+
assertCanRegister(type: string, instance: S, source: StrategySource): void;
|
|
29
|
+
/** Removes one exact programmatic registration without affecting fallback scopes. */
|
|
30
|
+
unregister(type: string, source: StrategySource, expected?: S): boolean;
|
|
24
31
|
/** Returns the explicit registry provenance attached by the plugin loader. */
|
|
25
32
|
getSource(instance: S): StrategySource;
|
|
26
33
|
/**
|
|
@@ -48,6 +55,18 @@ export declare class BaseStrategyRegistry<S> implements OnModuleInit {
|
|
|
48
55
|
* @returns
|
|
49
56
|
*/
|
|
50
57
|
list(organizationId?: string): S[];
|
|
58
|
+
listRegistrations(organizationId?: string): Array<{
|
|
59
|
+
type: string;
|
|
60
|
+
strategy: S;
|
|
61
|
+
source: StrategySource;
|
|
62
|
+
}>;
|
|
63
|
+
/** Returns every direct registration without applying request-scope fallback rules. */
|
|
64
|
+
listAllRegistrations(): Array<{
|
|
65
|
+
type: string;
|
|
66
|
+
strategy: S;
|
|
67
|
+
source: StrategySource;
|
|
68
|
+
}>;
|
|
69
|
+
private store;
|
|
51
70
|
}
|
|
52
71
|
/** Returns whether a discovered provider can carry decorator metadata. */
|
|
53
72
|
export declare function isStrategyInstance(instance: unknown): instance is object;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import type { IXpertToolset } from '@xpert-ai/contracts';
|
|
3
|
+
import type { ZodSchema } from 'zod/v3';
|
|
4
|
+
import type { IAgentMiddlewareContext, IAgentMiddlewareStrategy } from '../agent/middleware/strategy.interface';
|
|
5
|
+
import type { AgentMiddleware } from '../agent/middleware/types';
|
|
6
|
+
import { BuiltinToolset, type TBuiltinToolsetParams } from '../toolset/builtin';
|
|
7
|
+
import type { IToolsetStrategy } from '../toolset/strategy.interface';
|
|
8
|
+
import type { XpertToolProviderDescriptor, XpertToolProviderInstance } from './types';
|
|
9
|
+
export declare class DecoratedToolsetStrategy implements IToolsetStrategy<IXpertToolset> {
|
|
10
|
+
private readonly instance;
|
|
11
|
+
private readonly pluginName?;
|
|
12
|
+
private readonly pluginVersion?;
|
|
13
|
+
readonly descriptor: XpertToolProviderDescriptor;
|
|
14
|
+
readonly meta: IToolsetStrategy<IXpertToolset>['meta'];
|
|
15
|
+
constructor(instance: XpertToolProviderInstance, pluginName?: string, pluginVersion?: string);
|
|
16
|
+
validateConfig(): Promise<void>;
|
|
17
|
+
create(toolset: IXpertToolset, params?: TBuiltinToolsetParams): Promise<BuiltinToolset>;
|
|
18
|
+
createTools(): DynamicStructuredTool<ZodSchema>[];
|
|
19
|
+
}
|
|
20
|
+
export declare class DecoratedAgentMiddlewareStrategy implements IAgentMiddlewareStrategy<unknown> {
|
|
21
|
+
private readonly instance;
|
|
22
|
+
private readonly descriptor;
|
|
23
|
+
readonly provider: string;
|
|
24
|
+
readonly meta: any;
|
|
25
|
+
constructor(instance: XpertToolProviderInstance, descriptor: XpertToolProviderDescriptor, provider: string);
|
|
26
|
+
createMiddleware(options: unknown, context: IAgentMiddlewareContext): Promise<AgentMiddleware>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
3
|
+
import { AgentMiddlewareRegistry } from '../agent/middleware/strategy.registry';
|
|
4
|
+
import { StrategyBus } from '../core/strategy-bus';
|
|
5
|
+
import { ToolsetRegistry } from '../toolset/strategy.registry';
|
|
6
|
+
import { XpertToolProviderRegistry } from './registry';
|
|
7
|
+
/** Expands one decorated business provider into the existing Toolset and Middleware registries. */
|
|
8
|
+
export declare class XpertToolProviderCoordinator implements OnModuleInit, OnModuleDestroy {
|
|
9
|
+
private readonly discovery;
|
|
10
|
+
private readonly bus;
|
|
11
|
+
private readonly providerRegistry;
|
|
12
|
+
private readonly toolsetRegistry;
|
|
13
|
+
private readonly middlewareRegistry;
|
|
14
|
+
private subscription?;
|
|
15
|
+
private readonly processed;
|
|
16
|
+
constructor(discovery: DiscoveryService, bus: StrategyBus, providerRegistry: XpertToolProviderRegistry, toolsetRegistry: ToolsetRegistry, middlewareRegistry: AgentMiddlewareRegistry);
|
|
17
|
+
onModuleInit(): void;
|
|
18
|
+
onModuleDestroy(): void;
|
|
19
|
+
private expand;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { XpertToolOptions, XpertToolProviderOptions } from './types';
|
|
2
|
+
export declare const XPERT_TOOL_PROVIDER = "XPERT_TOOL_PROVIDER";
|
|
3
|
+
export declare const XPERT_TOOL_PROVIDER_METADATA = "XPERT_TOOL_PROVIDER_METADATA";
|
|
4
|
+
export declare const XPERT_TOOL_METHOD_METADATA = "XPERT_TOOL_METHOD_METADATA";
|
|
5
|
+
/** Marks one injectable business service as a reusable Tool provider and one native MCP service. */
|
|
6
|
+
export declare const XpertToolProvider: (options: XpertToolProviderOptions) => ClassDecorator;
|
|
7
|
+
/** Exposes one business method through an Agent Middleware, native MCP, or both. */
|
|
8
|
+
export declare const XpertTool: (options: XpertToolOptions) => MethodDecorator;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { XpertDecoratedToolDescriptor, XpertToolProviderDescriptor } from './types';
|
|
2
|
+
export declare function describeXpertToolProvider(instance: object): XpertToolProviderDescriptor;
|
|
3
|
+
export declare function getXpertToolMethod(instance: object, descriptor: XpertDecoratedToolDescriptor): (input: unknown, context: unknown) => unknown;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../strategy';
|
|
3
|
+
import type { XpertToolProviderInstance } from './types';
|
|
4
|
+
export declare class XpertToolProviderRegistry extends BaseStrategyRegistry<XpertToolProviderInstance> {
|
|
5
|
+
private readonly replacements;
|
|
6
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
7
|
+
upsert(candidate: unknown): void;
|
|
8
|
+
rollback(instance: XpertToolProviderInstance): void;
|
|
9
|
+
private assertUniqueClaims;
|
|
10
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { IconDefinition, I18nObject, JsonSchemaObjectType, McpRequiredContext, McpToolBehavior, TAgentMiddlewareMeta } from '@xpert-ai/contracts';
|
|
2
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
3
|
+
import type { ZodTypeAny, infer as ZodInfer } from 'zod/v3';
|
|
4
|
+
import type { AgentMiddleware } from '../agent/middleware/types';
|
|
5
|
+
import type { IAgentMiddlewareContext } from '../agent/middleware/strategy.interface';
|
|
6
|
+
import type { McpAppDefinition } from '../mcp/app';
|
|
7
|
+
import type { ToolExecutionContext, ToolHostApi, ToolPrincipal } from '../toolset/tool-execution-context';
|
|
8
|
+
import type { XpertToolAppBinding, XpertToolVisibility } from '../toolset/define-tool';
|
|
9
|
+
import type { PromiseOrValue } from '../types';
|
|
10
|
+
export type XpertBusinessToolSurface = 'middleware' | 'mcp';
|
|
11
|
+
export interface XpertToolProviderMiddlewareDefinition {
|
|
12
|
+
provider: string;
|
|
13
|
+
meta: TAgentMiddlewareMeta;
|
|
14
|
+
}
|
|
15
|
+
export interface XpertToolProviderOptions {
|
|
16
|
+
/** Stable Builtin Toolset provider key. */
|
|
17
|
+
provider: string;
|
|
18
|
+
/** Stable plugin resource identity. */
|
|
19
|
+
componentKey: string;
|
|
20
|
+
/** Human-readable MCP service name. */
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
instructions?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Legacy display hint. The host owns the public Publication slug and derives it from
|
|
26
|
+
* artifactNamespace, provider, and plugin scope.
|
|
27
|
+
* @deprecated Do not couple Provider definitions to a client or public endpoint name.
|
|
28
|
+
*/
|
|
29
|
+
slug?: string;
|
|
30
|
+
author?: string;
|
|
31
|
+
tags?: string[];
|
|
32
|
+
label?: I18nObject;
|
|
33
|
+
icon?: IconDefinition;
|
|
34
|
+
configSchema?: JsonSchemaObjectType;
|
|
35
|
+
defaultMiddleware?: string;
|
|
36
|
+
middlewares?: readonly XpertToolProviderMiddlewareDefinition[];
|
|
37
|
+
/** Static MCP App bundles published with this host-native Provider. */
|
|
38
|
+
apps?: readonly McpAppDefinition[];
|
|
39
|
+
}
|
|
40
|
+
export interface XpertMcpToolOptions {
|
|
41
|
+
behavior: McpToolBehavior;
|
|
42
|
+
requiredContext: readonly McpRequiredContext[];
|
|
43
|
+
visibility?: readonly XpertToolVisibility[];
|
|
44
|
+
/** Associates this Tool with one App declared by the owning Provider. */
|
|
45
|
+
app?: XpertToolAppBinding;
|
|
46
|
+
}
|
|
47
|
+
export interface XpertToolOptions<TInputSchema extends ZodTypeAny = ZodTypeAny, TOutputSchema extends ZodTypeAny = ZodTypeAny> {
|
|
48
|
+
name: string;
|
|
49
|
+
title?: string;
|
|
50
|
+
description: string;
|
|
51
|
+
inputSchema: TInputSchema;
|
|
52
|
+
outputSchema?: TOutputSchema;
|
|
53
|
+
/** true uses the class default, a string selects a declared group, false disables Middleware exposure. */
|
|
54
|
+
middleware?: true | string | false;
|
|
55
|
+
/** MCP exposure is opt-in. */
|
|
56
|
+
mcp?: XpertMcpToolOptions | false;
|
|
57
|
+
/** LangChain Tool metadata used only on the Agent Middleware surface. */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
export interface XpertBusinessToolContext {
|
|
61
|
+
surface: XpertBusinessToolSurface;
|
|
62
|
+
tenantId: string;
|
|
63
|
+
organizationId?: string | null;
|
|
64
|
+
principal: ToolPrincipal;
|
|
65
|
+
workspaceId?: string;
|
|
66
|
+
projectId?: string;
|
|
67
|
+
conversationId?: string;
|
|
68
|
+
threadId?: string;
|
|
69
|
+
xpertId?: string;
|
|
70
|
+
agentKey?: string;
|
|
71
|
+
executionId?: string;
|
|
72
|
+
requestId?: string;
|
|
73
|
+
traceId?: string;
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
host: ToolHostApi;
|
|
76
|
+
middlewareOptions?: unknown;
|
|
77
|
+
}
|
|
78
|
+
export type XpertDecoratedToolMethod<TInputSchema extends ZodTypeAny = ZodTypeAny, TOutputSchema extends ZodTypeAny = ZodTypeAny> = (input: ZodInfer<TInputSchema>, context: XpertBusinessToolContext) => PromiseOrValue<ZodInfer<TOutputSchema>>;
|
|
79
|
+
export interface XpertToolProviderInstance {
|
|
80
|
+
getMiddlewareExtensions?(provider: string, options: unknown, context: IAgentMiddlewareContext): PromiseOrValue<Omit<AgentMiddleware, 'name' | 'tools'>>;
|
|
81
|
+
}
|
|
82
|
+
export interface XpertDecoratedToolDescriptor {
|
|
83
|
+
methodName: string;
|
|
84
|
+
middlewareProvider?: string;
|
|
85
|
+
options: Readonly<XpertToolOptions>;
|
|
86
|
+
}
|
|
87
|
+
export interface XpertToolProviderDescriptor {
|
|
88
|
+
options: Readonly<XpertToolProviderOptions>;
|
|
89
|
+
tools: readonly XpertDecoratedToolDescriptor[];
|
|
90
|
+
}
|
|
91
|
+
export interface XpertAgentToolRunnableConfig extends RunnableConfig {
|
|
92
|
+
configurable?: RunnableConfig['configurable'] & {
|
|
93
|
+
tool_call_id?: string;
|
|
94
|
+
executionId?: string;
|
|
95
|
+
traceId?: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export type XpertMcpExecutionContext = ToolExecutionContext;
|