@xpert-ai/plugin-sdk 3.16.1 → 3.17.1
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 +21 -0
- package/_extends.cjs.js +14 -0
- package/_extends.esm.js +12 -0
- package/collaboration-client.cjs.js +392 -8
- package/collaboration-client.esm.js +389 -1
- package/index.cjs.js +500 -285
- package/index.esm.js +444 -247
- package/model-provider-http-client.cjs.default.js +1 -0
- package/model-provider-http-client.cjs.js +118 -0
- package/model-provider-http-client.cjs.mjs +2 -0
- package/model-provider-http-client.d.ts +1 -0
- package/model-provider-http-client.esm.js +115 -0
- package/model-provider-toolset.cjs.default.js +1 -0
- package/model-provider-toolset.cjs.js +12 -0
- package/model-provider-toolset.cjs.mjs +2 -0
- package/model-provider-toolset.d.ts +1 -0
- package/model-provider-toolset.esm.js +6 -0
- package/model-provider.cjs.js +348 -0
- package/model-provider.esm.js +328 -0
- package/package.json +14 -2
- package/src/index.d.ts +1 -0
- package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +3 -0
- package/src/lib/agent/middleware/index.d.ts +1 -0
- package/src/lib/agent/middleware/model-output-validation-error.d.ts +27 -0
- package/src/lib/agent/middleware/runtime.d.ts +43 -4
- package/src/lib/ai-model/abstract-provider.d.ts +2 -2
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -3
- package/src/lib/ai-model/ai-model.d.ts +4 -1
- package/src/lib/ai-model/index.d.ts +2 -0
- package/src/lib/ai-model/llm.d.ts +49 -3
- package/src/lib/ai-model/managed-aigc-job.d.ts +37 -0
- package/src/lib/ai-model/model-provider-http-client.d.ts +51 -0
- package/src/lib/ai-model/pricing.d.ts +13 -1
- package/src/lib/ai-model/types/aigc.d.ts +39 -0
- package/src/lib/ai-model/types/index.d.ts +1 -0
- package/src/lib/ai-model/types/model.d.ts +11 -4
- package/src/lib/core/runtime-capability.d.ts +2 -0
- package/src/lib/evolution/index.d.ts +4 -0
- package/src/lib/evolution/provider.decorator.d.ts +2 -0
- package/src/lib/evolution/provider.registry.d.ts +7 -0
- package/src/lib/evolution/runtime-capability.d.ts +3 -0
- package/src/lib/managed-queue/index.d.ts +3 -1
- package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +59 -1
- package/src/lib/runtime/capabilities/knowledgebase.d.ts +95 -3
- package/src/lib/runtime/capabilities/workspace-files.d.ts +5 -0
- package/src/lib/toolset/builtin.d.ts +28 -0
- package/src/lib/toolset/index.d.ts +1 -0
- package/src/lib/toolset/model-provider.d.ts +31 -0
- package/src/lib/vectorstore/strategy.interface.d.ts +3 -0
- package/src/model-provider-http-client.d.ts +1 -0
- package/src/model-provider-toolset.d.ts +1 -0
- package/collaboration-client.cjs2.js +0 -406
- package/collaboration-client.esm2.js +0 -398
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { AiModelTypeEnum } from '@xpert-ai/contracts';
|
|
2
|
+
import { _ as _extends } from './_extends.esm.js';
|
|
3
|
+
import { Logger } from '@nestjs/common';
|
|
4
|
+
import { BaseToolkit, StructuredTool } from '@langchain/core/tools';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base ability for all toolsets
|
|
9
|
+
*/ class BaseToolset extends BaseToolkit {
|
|
10
|
+
/**
|
|
11
|
+
* Async init tools
|
|
12
|
+
*
|
|
13
|
+
* @returns
|
|
14
|
+
*/ async initTools() {
|
|
15
|
+
return this.tools;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get one tool
|
|
19
|
+
*
|
|
20
|
+
* @param toolName
|
|
21
|
+
* @returns
|
|
22
|
+
*/ getTool(toolName) {
|
|
23
|
+
var _this_getTools;
|
|
24
|
+
return (_this_getTools = this.getTools()) == null ? void 0 : _this_getTools.find((tool)=>tool.name === toolName);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get state variables config
|
|
28
|
+
*
|
|
29
|
+
* @returns State variables
|
|
30
|
+
*/ async getVariables() {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Close all (connections).
|
|
35
|
+
*/ async close() {
|
|
36
|
+
//
|
|
37
|
+
}
|
|
38
|
+
constructor(params){
|
|
39
|
+
super();
|
|
40
|
+
this.params = params;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class BaseTool extends StructuredTool {
|
|
44
|
+
constructor(...args){
|
|
45
|
+
super(...args);
|
|
46
|
+
this.schema = z.object({
|
|
47
|
+
input: z.string().optional()
|
|
48
|
+
}).transform((obj)=>obj.input);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class BuiltinToolset extends BaseToolset {
|
|
53
|
+
get tenantId() {
|
|
54
|
+
var _this_params;
|
|
55
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.tenantId;
|
|
56
|
+
}
|
|
57
|
+
get organizationId() {
|
|
58
|
+
var _this_params;
|
|
59
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.organizationId;
|
|
60
|
+
}
|
|
61
|
+
get commandBus() {
|
|
62
|
+
var _this_params;
|
|
63
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.commandBus;
|
|
64
|
+
}
|
|
65
|
+
get queryBus() {
|
|
66
|
+
var _this_params;
|
|
67
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.queryBus;
|
|
68
|
+
}
|
|
69
|
+
get xpertId() {
|
|
70
|
+
var _this_params;
|
|
71
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.xpertId;
|
|
72
|
+
}
|
|
73
|
+
get modelRuntime() {
|
|
74
|
+
var _this_params;
|
|
75
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.modelRuntime;
|
|
76
|
+
}
|
|
77
|
+
get managedQueue() {
|
|
78
|
+
var _this_params;
|
|
79
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.managedQueue;
|
|
80
|
+
}
|
|
81
|
+
get pluginScopeKey() {
|
|
82
|
+
var _this_params;
|
|
83
|
+
return (_this_params = this.params) == null ? void 0 : _this_params.pluginScopeKey;
|
|
84
|
+
}
|
|
85
|
+
async validateCredentials(credentials) {
|
|
86
|
+
await this._validateCredentials(credentials);
|
|
87
|
+
}
|
|
88
|
+
async _validateCredentials(credentials) {
|
|
89
|
+
throw new Error('Method not implemented.');
|
|
90
|
+
}
|
|
91
|
+
getId() {
|
|
92
|
+
var _this_toolset;
|
|
93
|
+
return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.id;
|
|
94
|
+
}
|
|
95
|
+
getCredentials() {
|
|
96
|
+
var _this_toolset;
|
|
97
|
+
return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.credentials;
|
|
98
|
+
}
|
|
99
|
+
getToolTitle(name) {
|
|
100
|
+
var _this_toolset_tools, _this_toolset, _tool_schema;
|
|
101
|
+
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);
|
|
102
|
+
const identity = tool == null ? void 0 : (_tool_schema = tool.schema) == null ? void 0 : _tool_schema.identity;
|
|
103
|
+
if (identity) {
|
|
104
|
+
return identity.label;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get credentials schema
|
|
110
|
+
*
|
|
111
|
+
* @returns Credentials schema
|
|
112
|
+
*/ getCredentialsSchema() {
|
|
113
|
+
return _extends({}, this.credentialsSchema);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get toolset entity
|
|
117
|
+
*
|
|
118
|
+
* @returns XpertToolset
|
|
119
|
+
*/ getToolset() {
|
|
120
|
+
return this.toolset;
|
|
121
|
+
}
|
|
122
|
+
getName() {
|
|
123
|
+
var _this_getToolset;
|
|
124
|
+
return (_this_getToolset = this.getToolset()) == null ? void 0 : _this_getToolset.name;
|
|
125
|
+
}
|
|
126
|
+
constructor(providerName, toolset, params){
|
|
127
|
+
super(params);
|
|
128
|
+
this.logger = new Logger(this.constructor.name);
|
|
129
|
+
this.providerName = providerName;
|
|
130
|
+
this.toolset = toolset;
|
|
131
|
+
this.params = params;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
BuiltinToolset.provider = '';
|
|
135
|
+
|
|
136
|
+
function createRuntimeCapability(id, options = {}) {
|
|
137
|
+
return Object.freeze({
|
|
138
|
+
id,
|
|
139
|
+
description: options.description
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const XPERT_RUNTIME_CAPABILITIES_TOKEN = 'XPERT_RUNTIME_CAPABILITIES';
|
|
143
|
+
class DefaultRuntimeCapabilityRegistry {
|
|
144
|
+
register(key, implementation) {
|
|
145
|
+
this.capabilities.set(runtimeCapabilityId(key), implementation);
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
has(key) {
|
|
149
|
+
return this.capabilities.has(runtimeCapabilityId(key));
|
|
150
|
+
}
|
|
151
|
+
get(key) {
|
|
152
|
+
return this.capabilities.get(runtimeCapabilityId(key));
|
|
153
|
+
}
|
|
154
|
+
require(key) {
|
|
155
|
+
const implementation = this.get(key);
|
|
156
|
+
if (!implementation) {
|
|
157
|
+
throw new Error(`Runtime capability '${runtimeCapabilityId(key)}' is not available`);
|
|
158
|
+
}
|
|
159
|
+
return implementation;
|
|
160
|
+
}
|
|
161
|
+
constructor(entries = []){
|
|
162
|
+
this.capabilities = new Map();
|
|
163
|
+
entries.forEach(([key, implementation])=>this.register(key, implementation));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function runtimeCapabilityId(key) {
|
|
167
|
+
return typeof key === 'string' ? key : key.id;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const KnowledgebaseRuntimeCapability = createRuntimeCapability('platform.knowledgebase', {
|
|
171
|
+
description: 'List, search, and write chunks in platform knowledgebases.'
|
|
172
|
+
});
|
|
173
|
+
const KnowledgebaseProvisioningRuntimeCapability = createRuntimeCapability('platform.knowledgebase.provisioning', {
|
|
174
|
+
description: 'Idempotently provision managed platform knowledgebases and connect them to an Agent.'
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const KnowledgebaseDocumentsRuntimeCapability = createRuntimeCapability('platform.knowledgebase.documents', {
|
|
178
|
+
description: 'Upload, import, create, process, inspect, and delete persistent knowledgebase documents.'
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const ActorTokenRuntimeCapability = createRuntimeCapability('platform.actor-token', {
|
|
182
|
+
description: 'Mint a short-lived host-issued actor bearer token for outbound API calls.'
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const ArtifactsRuntimeCapability = createRuntimeCapability('platform.artifacts', {
|
|
186
|
+
description: 'Create, version, preview, download, share, archive, and delete platform-managed plugin and Agent artifacts.'
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/** Stable source identifier for portable workspace file references. */ const WORKSPACE_FILES_SOURCE = 'platform.workspace.files';
|
|
190
|
+
const WorkspaceFilesRuntimeCapability = createRuntimeCapability('platform.workspace.files', {
|
|
191
|
+
description: 'Upload, understand, resolve, read, and delete raw files in Xpert workspace volumes.'
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
/** Stable machine-readable failures emitted by the Sandbox Jobs capability. */ const SANDBOX_JOB_ERROR_CODES = [
|
|
195
|
+
'SANDBOX_ACTION_UNAVAILABLE',
|
|
196
|
+
'SANDBOX_ACTION_INVALID',
|
|
197
|
+
'SANDBOX_PROFILE_UNAVAILABLE',
|
|
198
|
+
'SANDBOX_RUNTIME_UNAVAILABLE',
|
|
199
|
+
'SANDBOX_VERSION_MISMATCH',
|
|
200
|
+
'SANDBOX_CAPACITY_UNAVAILABLE',
|
|
201
|
+
'SANDBOX_START_FAILED',
|
|
202
|
+
'BROWSER_LAUNCH_FAILED',
|
|
203
|
+
'EXPORT_TIMEOUT',
|
|
204
|
+
'EXPORT_OOM',
|
|
205
|
+
'EXPORT_MEDIA_FAILED',
|
|
206
|
+
'EXPORT_INPUT_INVALID',
|
|
207
|
+
'EXPORT_OUTPUT_INVALID',
|
|
208
|
+
'SANDBOX_CANCELLED'
|
|
209
|
+
];
|
|
210
|
+
/** Line prefix used by trusted Actions to report structured, provider-neutral progress. */ const SANDBOX_JOB_PROGRESS_PREFIX = 'XPERT_SANDBOX_PROGRESS ';
|
|
211
|
+
/** Error carrying retry policy and Job identity across plugin queue handlers. */ class SandboxJobRuntimeError extends Error {
|
|
212
|
+
constructor(code, message, retryable, jobId){
|
|
213
|
+
super(message);
|
|
214
|
+
this.code = code;
|
|
215
|
+
this.retryable = retryable;
|
|
216
|
+
this.jobId = jobId;
|
|
217
|
+
this.name = 'SandboxJobRuntimeError';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const SANDBOX_JOB_ERROR_CODE_SET = new Set(SANDBOX_JOB_ERROR_CODES);
|
|
221
|
+
/** Narrows an unknown failure to the structured Sandbox Jobs runtime error contract. */ function isSandboxJobRuntimeError(error) {
|
|
222
|
+
if (error instanceof SandboxJobRuntimeError) return true;
|
|
223
|
+
if (typeof error !== 'object' || error === null) return false;
|
|
224
|
+
// Dynamically loaded plugins may resolve another Plugin SDK module instance,
|
|
225
|
+
// so class identity is not a reliable runtime boundary. Validate the stable shape.
|
|
226
|
+
const candidate = error;
|
|
227
|
+
return candidate.name === 'SandboxJobRuntimeError' && typeof candidate.message === 'string' && typeof candidate.code === 'string' && SANDBOX_JOB_ERROR_CODE_SET.has(candidate.code) && typeof candidate.retryable === 'boolean' && (candidate.jobId === undefined || typeof candidate.jobId === 'string');
|
|
228
|
+
}
|
|
229
|
+
/** Runtime capability key used to resolve SandboxJobsApi from the platform registry. */ const SandboxJobsRuntimeCapability = createRuntimeCapability('platform.sandbox.jobs', {
|
|
230
|
+
description: 'Run registered plugin actions in isolated, short-lived Sandbox Runtime jobs.'
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Shared host-runtime plumbing for built-in tools backed by a configured model provider.
|
|
235
|
+
* Provider request/response semantics remain owned by each plugin.
|
|
236
|
+
*/ class ModelProviderBuiltinToolset extends BuiltinToolset {
|
|
237
|
+
async _validateCredentials(_credentials) {
|
|
238
|
+
await this.getModelProviderRuntime();
|
|
239
|
+
}
|
|
240
|
+
getModelProviderRuntime() {
|
|
241
|
+
var _this_modelRuntime;
|
|
242
|
+
if (!((_this_modelRuntime = this.modelRuntime) == null ? void 0 : _this_modelRuntime.getModelProvider)) {
|
|
243
|
+
throw new Error(this.modelProviderOptions.missingProviderMessage);
|
|
244
|
+
}
|
|
245
|
+
var _this_modelProvider;
|
|
246
|
+
(_this_modelProvider = this.modelProvider) != null ? _this_modelProvider : this.modelProvider = this.modelRuntime.getModelProvider(this.modelProviderOptions.modelProviderName);
|
|
247
|
+
return this.modelProvider;
|
|
248
|
+
}
|
|
249
|
+
getModelProviderCredential(modelProvider) {
|
|
250
|
+
const scheme = this.modelProviderOptions.authorizationScheme;
|
|
251
|
+
const match = new RegExp(`^${scheme}\\s+(.+)$`, 'i').exec(modelProvider.authorization.trim());
|
|
252
|
+
if (!(match == null ? void 0 : match[1])) {
|
|
253
|
+
throw new Error(this.modelProviderOptions.invalidCredentialsMessage);
|
|
254
|
+
}
|
|
255
|
+
return match[1];
|
|
256
|
+
}
|
|
257
|
+
getWorkspaceFiles() {
|
|
258
|
+
var _this_runtimeCapabilities;
|
|
259
|
+
const workspaceFiles = (_this_runtimeCapabilities = this.runtimeCapabilities) == null ? void 0 : _this_runtimeCapabilities.get(WorkspaceFilesRuntimeCapability);
|
|
260
|
+
if (!workspaceFiles) {
|
|
261
|
+
throw new Error(this.modelProviderOptions.missingWorkspaceMessage);
|
|
262
|
+
}
|
|
263
|
+
return workspaceFiles;
|
|
264
|
+
}
|
|
265
|
+
createWorkspaceScope() {
|
|
266
|
+
var _this_params, _this_params1, _this_params2;
|
|
267
|
+
const projectId = normalizeOptionalString((_this_params = this.params) == null ? void 0 : _this_params.projectId);
|
|
268
|
+
if (projectId) {
|
|
269
|
+
var _this_params3, _this_params4;
|
|
270
|
+
return {
|
|
271
|
+
tenantId: normalizeOptionalString((_this_params3 = this.params) == null ? void 0 : _this_params3.tenantId),
|
|
272
|
+
userId: normalizeOptionalString((_this_params4 = this.params) == null ? void 0 : _this_params4.userId),
|
|
273
|
+
catalog: 'projects',
|
|
274
|
+
scopeId: projectId,
|
|
275
|
+
projectId
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const xpertId = normalizeOptionalString(this.xpertId);
|
|
279
|
+
if (!xpertId) return undefined;
|
|
280
|
+
return {
|
|
281
|
+
tenantId: normalizeOptionalString((_this_params1 = this.params) == null ? void 0 : _this_params1.tenantId),
|
|
282
|
+
userId: normalizeOptionalString((_this_params2 = this.params) == null ? void 0 : _this_params2.userId),
|
|
283
|
+
catalog: 'xperts',
|
|
284
|
+
scopeId: xpertId,
|
|
285
|
+
xpertId,
|
|
286
|
+
isolateByUser: false
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
async createAsyncModelClient(model, modality, purpose = 'invoke') {
|
|
290
|
+
const modelProvider = await this.getModelProviderRuntime();
|
|
291
|
+
const copilotId = normalizeOptionalString(modelProvider.copilotId);
|
|
292
|
+
if (!copilotId) {
|
|
293
|
+
throw new Error(this.modelProviderOptions.missingProviderMessage);
|
|
294
|
+
}
|
|
295
|
+
const modelType = modality === 'image' ? AiModelTypeEnum.IMAGE : AiModelTypeEnum.VIDEO;
|
|
296
|
+
return this.modelRuntime.createModelClient({
|
|
297
|
+
copilotId,
|
|
298
|
+
model,
|
|
299
|
+
modelType
|
|
300
|
+
}, {
|
|
301
|
+
purpose
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
async createModelClient(model, modality) {
|
|
305
|
+
const modelProvider = await this.getModelProviderRuntime();
|
|
306
|
+
const copilotId = normalizeOptionalString(modelProvider.copilotId);
|
|
307
|
+
if (!copilotId) {
|
|
308
|
+
throw new Error(this.modelProviderOptions.missingProviderMessage);
|
|
309
|
+
}
|
|
310
|
+
const modelType = modality === 'image' ? AiModelTypeEnum.IMAGE : AiModelTypeEnum.VIDEO;
|
|
311
|
+
return this.modelRuntime.createModelClient({
|
|
312
|
+
copilotId,
|
|
313
|
+
model,
|
|
314
|
+
modelType
|
|
315
|
+
}, {});
|
|
316
|
+
}
|
|
317
|
+
constructor(modelProviderOptions, toolset, runtimeCapabilities, params){
|
|
318
|
+
super(modelProviderOptions.toolsetProviderName, toolset, params);
|
|
319
|
+
this.modelProviderOptions = modelProviderOptions;
|
|
320
|
+
this.runtimeCapabilities = runtimeCapabilities;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function normalizeOptionalString(value) {
|
|
324
|
+
const normalized = value == null ? void 0 : value.trim();
|
|
325
|
+
return normalized || undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export { ActorTokenRuntimeCapability as A, BaseTool as B, DefaultRuntimeCapabilityRegistry as D, KnowledgebaseDocumentsRuntimeCapability as K, ModelProviderBuiltinToolset as M, SANDBOX_JOB_ERROR_CODES as S, WORKSPACE_FILES_SOURCE as W, XPERT_RUNTIME_CAPABILITIES_TOKEN as X, ArtifactsRuntimeCapability as a, BaseToolset as b, createRuntimeCapability as c, BuiltinToolset as d, KnowledgebaseProvisioningRuntimeCapability as e, KnowledgebaseRuntimeCapability as f, SANDBOX_JOB_PROGRESS_PREFIX as g, SandboxJobRuntimeError as h, SandboxJobsRuntimeCapability as i, WorkspaceFilesRuntimeCapability as j, isSandboxJobRuntimeError as k };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.1",
|
|
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.
|
|
20
|
+
"@xpert-ai/contracts": "3.17.1",
|
|
21
21
|
"express": "^4.22.1",
|
|
22
22
|
"js-tiktoken": "^1.0.21"
|
|
23
23
|
},
|
|
@@ -56,6 +56,18 @@
|
|
|
56
56
|
"types": "./connector.d.ts",
|
|
57
57
|
"import": "./connector.cjs.mjs",
|
|
58
58
|
"default": "./connector.cjs.js"
|
|
59
|
+
},
|
|
60
|
+
"./model-provider-toolset": {
|
|
61
|
+
"module": "./model-provider-toolset.esm.js",
|
|
62
|
+
"types": "./model-provider-toolset.d.ts",
|
|
63
|
+
"import": "./model-provider-toolset.cjs.mjs",
|
|
64
|
+
"default": "./model-provider-toolset.cjs.js"
|
|
65
|
+
},
|
|
66
|
+
"./model-provider-http-client": {
|
|
67
|
+
"module": "./model-provider-http-client.esm.js",
|
|
68
|
+
"types": "./model-provider-http-client.d.ts",
|
|
69
|
+
"import": "./model-provider-http-client.cjs.mjs",
|
|
70
|
+
"default": "./model-provider-http-client.cjs.js"
|
|
59
71
|
}
|
|
60
72
|
},
|
|
61
73
|
"types": "./index.d.ts"
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JSONValue } from '@xpert-ai/contracts';
|
|
1
2
|
export type AgentMiddlewareAssistantTaskStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'interrupted' | 'unknown';
|
|
2
3
|
export type AgentMiddlewareAssistantTaskFile = {
|
|
3
4
|
id?: string;
|
|
@@ -21,6 +22,8 @@ export type AgentMiddlewareAssistantTaskInput = {
|
|
|
21
22
|
clientMessageId?: string;
|
|
22
23
|
prompt: string;
|
|
23
24
|
files?: AgentMiddlewareAssistantTaskFile[];
|
|
25
|
+
/** Additional bounded human-input fields exposed to runtime-state fixed filters. */
|
|
26
|
+
humanInput?: Record<string, JSONValue>;
|
|
24
27
|
context?: Record<string, unknown>;
|
|
25
28
|
};
|
|
26
29
|
export type AgentMiddlewareAssistantTaskResult = {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const MODEL_OUTPUT_VALIDATION_ERROR_CODE: "MODEL_OUTPUT_VALIDATION_ERROR";
|
|
2
|
+
export type ModelOutputValidationIssue = {
|
|
3
|
+
toolName?: string;
|
|
4
|
+
error: string;
|
|
5
|
+
fieldName?: string;
|
|
6
|
+
characterOffset?: number;
|
|
7
|
+
hint?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ModelOutputRepairContext = {
|
|
10
|
+
kind: 'invalid_tool_calls';
|
|
11
|
+
issues: ModelOutputValidationIssue[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Signals that the provider returned a model response which could not be
|
|
15
|
+
* accepted, but can be regenerated safely because no tool was executed.
|
|
16
|
+
*
|
|
17
|
+
* Keep `repairContext` compact and free of raw tool arguments. Model
|
|
18
|
+
* middleware may use it as retry-local feedback, so it must never contain
|
|
19
|
+
* credentials, complete documents, or other unbounded model output.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ModelOutputValidationError extends Error {
|
|
22
|
+
readonly repairContext: ModelOutputRepairContext;
|
|
23
|
+
readonly code: "MODEL_OUTPUT_VALIDATION_ERROR";
|
|
24
|
+
readonly retryable = true;
|
|
25
|
+
constructor(message: string, repairContext: ModelOutputRepairContext);
|
|
26
|
+
}
|
|
27
|
+
export declare function isModelOutputValidationError(error: unknown): error is ModelOutputValidationError;
|
|
@@ -3,9 +3,9 @@ import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
|
3
3
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
4
4
|
import type { Runtime as LangGraphRuntime } from '@langchain/langgraph';
|
|
5
5
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
6
|
-
import { ICopilotModel,
|
|
6
|
+
import { ICopilotModel, IXpertAgentExecution, JSONValue, ModelUsagePricingSnapshot, ModelUsageReport, ModelUsageReportResult, ModelUsagePricingContext, TSandboxConfigurable } from '@xpert-ai/contracts';
|
|
7
7
|
import { Subscriber } from 'rxjs';
|
|
8
|
-
import { IRerank } from '../../ai-model/types';
|
|
8
|
+
import { AIGCModelClient, AsyncAIGCModelClient, IRerank, TLLMUsage } from '../../ai-model/types';
|
|
9
9
|
import type { RuntimeCapabilityRegistry } from '../../core';
|
|
10
10
|
export * from './runtime-capability';
|
|
11
11
|
export * from './capabilities';
|
|
@@ -64,11 +64,48 @@ export type Runtime<TContext = unknown> = Partial<Omit<LangGraphRuntime<TContext
|
|
|
64
64
|
[key: string]: unknown;
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
-
export type AgentMiddlewareModelClient = BaseLanguageModel | BaseChatModel | Embeddings | IRerank;
|
|
67
|
+
export type AgentMiddlewareModelClient = BaseLanguageModel | BaseChatModel | Embeddings | IRerank | AIGCModelClient | AsyncAIGCModelClient;
|
|
68
68
|
export type AgentMiddlewareCreateModelClientOptions = {
|
|
69
69
|
abortController?: AbortController;
|
|
70
|
-
usageCallback
|
|
70
|
+
usageCallback?: (tokens: TLLMUsage) => void | Promise<void>;
|
|
71
|
+
/** `observe` reads an existing asynchronous task and must not consume generation quota. */
|
|
72
|
+
purpose?: 'invoke' | 'observe';
|
|
71
73
|
};
|
|
74
|
+
export type AgentMiddlewareModelProviderConnection = {
|
|
75
|
+
/** Stable host-owned model provider configuration boundary. */
|
|
76
|
+
providerScopeId: string;
|
|
77
|
+
/** Host-owned Copilot identity used for usage accounting. */
|
|
78
|
+
copilotId?: string;
|
|
79
|
+
/** Ownership scope of the resolved Provider configuration. */
|
|
80
|
+
organizationId?: string | null;
|
|
81
|
+
provider: string;
|
|
82
|
+
baseURL: string;
|
|
83
|
+
authorization: string;
|
|
84
|
+
/** Resolve the model YAML price rule and freeze it for one invocation. */
|
|
85
|
+
resolvePricingSnapshot?: (context: ModelUsagePricingContext) => Promise<ModelUsagePricingSnapshot>;
|
|
86
|
+
/** Persist final authoritative usage and calculate its charge exactly once. */
|
|
87
|
+
reportUsage(report: ModelUsageReport): Promise<ModelUsageReportResult>;
|
|
88
|
+
};
|
|
89
|
+
export type AgentMiddlewareRuntimeScope = {
|
|
90
|
+
tenantId?: string | null;
|
|
91
|
+
organizationId?: string | null;
|
|
92
|
+
providerScopeId?: string | null;
|
|
93
|
+
userId?: string | null;
|
|
94
|
+
workspaceId?: string | null;
|
|
95
|
+
projectId?: string | null;
|
|
96
|
+
xpertId?: string | null;
|
|
97
|
+
xpertName?: string | null;
|
|
98
|
+
conversationId?: string | null;
|
|
99
|
+
agentKey?: string | null;
|
|
100
|
+
executionId?: string | null;
|
|
101
|
+
usageCallback?: (usage: TLLMUsage) => void | Promise<void>;
|
|
102
|
+
workspaceRoot?: string | null;
|
|
103
|
+
workspacePath?: string | null;
|
|
104
|
+
};
|
|
105
|
+
export interface AgentMiddlewareRuntimeServiceApi {
|
|
106
|
+
createScopedApi(scope?: AgentMiddlewareRuntimeScope): AgentMiddlewareRuntimeApi;
|
|
107
|
+
}
|
|
108
|
+
export declare const XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN = "XPERT_AGENT_MIDDLEWARE_RUNTIME";
|
|
72
109
|
export type AgentMiddlewareWrapWorkflowNodeExecutionResult<T> = {
|
|
73
110
|
output?: string | JSONValue;
|
|
74
111
|
state: T;
|
|
@@ -97,6 +134,8 @@ export type AgentMiddlewareEvent = {
|
|
|
97
134
|
};
|
|
98
135
|
export interface AgentMiddlewareRuntimeApi {
|
|
99
136
|
createModelClient<T = AgentMiddlewareModelClient>(copilotModel: ICopilotModel, options: AgentMiddlewareCreateModelClientOptions): Promise<T>;
|
|
137
|
+
/** Resolve an enabled model provider connection in the current tenant and organization scope. */
|
|
138
|
+
getModelProvider?(provider: string): Promise<AgentMiddlewareModelProviderConnection>;
|
|
100
139
|
wrapWorkflowNodeExecution<T>(run: (execution: Partial<IXpertAgentExecution>) => Promise<AgentMiddlewareWrapWorkflowNodeExecutionResult<T>>, params: AgentMiddlewareWrapWorkflowNodeExecutionParams): Promise<T>;
|
|
101
140
|
emitMiddlewareEvent?(event: AgentMiddlewareEvent): Promise<void> | void;
|
|
102
141
|
capabilities?: RuntimeCapabilityRegistry;
|
|
@@ -5,7 +5,7 @@ import { AIModelEntity, AiModelTypeEnum, IAiProviderEntity, ICopilotModel, Provi
|
|
|
5
5
|
import { Logger } from '@nestjs/common';
|
|
6
6
|
import { AIModel } from './ai-model';
|
|
7
7
|
import { IAIModelProviderStrategy } from './ai-model-provider.interface';
|
|
8
|
-
import { TChatModelOptions, IRerank } from './types/';
|
|
8
|
+
import { AIGCModelClient, AsyncAIGCModelClient, TChatModelOptions, IRerank } from './types/';
|
|
9
9
|
export declare abstract class ModelProvider implements IAIModelProviderStrategy {
|
|
10
10
|
readonly logger: Logger;
|
|
11
11
|
protected _name?: string;
|
|
@@ -37,5 +37,5 @@ export declare abstract class ModelProvider implements IAIModelProviderStrategy
|
|
|
37
37
|
getProviderModels(modelType?: AiModelTypeEnum, onlyActive?: boolean): ProviderModel[];
|
|
38
38
|
getSystemProviderModels(modelTypes: AiModelTypeEnum[]): any[];
|
|
39
39
|
getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel<import("@langchain/core/language_models/chat_models").BaseChatModelCallOptions, import("@langchain/core/messages").AIMessageChunk>;
|
|
40
|
-
getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: TChatModelOptions): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank>;
|
|
40
|
+
getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: TChatModelOptions): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank | AIGCModelClient | AsyncAIGCModelClient>;
|
|
41
41
|
}
|
|
@@ -2,7 +2,7 @@ import { AiModelTypeEnum, IAiProviderEntity, ICopilotModel, ProviderModel, AIMod
|
|
|
2
2
|
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
3
3
|
import { Embeddings } from '@langchain/core/embeddings';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
|
-
import { IRerank } from './types';
|
|
5
|
+
import { AIGCModelClient, AsyncAIGCModelClient, IRerank } from './types';
|
|
6
6
|
import { AIModel } from './ai-model';
|
|
7
7
|
export interface IAIModelProviderStrategy {
|
|
8
8
|
/**
|
|
@@ -29,9 +29,9 @@ export interface IAIModelProviderStrategy {
|
|
|
29
29
|
*/
|
|
30
30
|
getModels(modelType: AiModelTypeEnum): Promise<AIModelEntity[]>;
|
|
31
31
|
/**
|
|
32
|
-
* Return a directly usable model instance (LLM / Embedding / TTS / Rerank)
|
|
32
|
+
* Return a directly usable model instance (LLM / Embedding / TTS / Rerank / AIGC)
|
|
33
33
|
*/
|
|
34
|
-
getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: Record<string, any>): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank>;
|
|
34
|
+
getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: Record<string, any>): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank | AIGCModelClient | AsyncAIGCModelClient>;
|
|
35
35
|
/**
|
|
36
36
|
* Return the defined provider models (metadata)
|
|
37
37
|
*/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
-
import { AIModelEntity, AiModelTypeEnum, ICopilotModel, ParameterRule, PriceInfo, PriceType } from '@xpert-ai/contracts';
|
|
2
|
+
import { AIModelEntity, AiModelTypeEnum, ICopilotModel, ModelUsagePricingContext, ModelUsagePricingSnapshot, ParameterRule, PriceInfo, PriceType } from '@xpert-ai/contracts';
|
|
3
3
|
import { Logger } from '@nestjs/common';
|
|
4
4
|
import { ModelProvider } from './abstract-provider';
|
|
5
|
+
import type { AIGCModelClient, AsyncAIGCModelClient } from './types/aigc';
|
|
5
6
|
import { IAIModel, TChatModelOptions } from './types/model';
|
|
6
7
|
import { ModelProfile } from './types/profile';
|
|
7
8
|
export declare abstract class AIModel implements IAIModel {
|
|
@@ -13,7 +14,9 @@ export declare abstract class AIModel implements IAIModel {
|
|
|
13
14
|
constructor(modelProvider: ModelProvider, modelType: AiModelTypeEnum);
|
|
14
15
|
abstract validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
|
|
15
16
|
getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
|
|
17
|
+
getAIGCModel(copilotModel: ICopilotModel, options?: TChatModelOptions): AIGCModelClient | AsyncAIGCModelClient;
|
|
16
18
|
getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
|
|
19
|
+
getUsagePricingSnapshot(model: string, credentials: Record<string, any>, context: ModelUsagePricingContext): ModelUsagePricingSnapshot;
|
|
17
20
|
protected getModelPath(): string;
|
|
18
21
|
predefinedModels(): AIModelEntity[];
|
|
19
22
|
getModelSchema(model: string, credentials?: Record<string, any>): AIModelEntity | null;
|
|
@@ -5,7 +5,9 @@ export * from './abstract-provider';
|
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './llm';
|
|
7
7
|
export * from './pricing';
|
|
8
|
+
export * from './managed-aigc-job';
|
|
8
9
|
export * from './errors';
|
|
9
10
|
export * from './openai-compatible';
|
|
11
|
+
export * from './model-provider-http-client';
|
|
10
12
|
export * from './utils/index';
|
|
11
13
|
export * from './commands/index';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AIModelEntity, ICopilot, ILLMUsage, ParameterRule, TTokenUsage } from '@xpert-ai/contracts';
|
|
2
2
|
import { Logger } from '@nestjs/common';
|
|
3
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
3
4
|
import { LLMResult } from '@langchain/core/outputs';
|
|
4
5
|
import { AIModel } from './ai-model';
|
|
5
6
|
import { TChatModelOptions } from './types/';
|
|
@@ -32,10 +33,55 @@ export declare abstract class LargeLanguageModel extends AIModel {
|
|
|
32
33
|
#private;
|
|
33
34
|
protected startedAt: DOMHighResTimeStamp;
|
|
34
35
|
protected _commonParameterRules(model: string): ParameterRule[];
|
|
35
|
-
protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number): ILLMUsage;
|
|
36
|
+
protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number, startedAt?: number): ILLMUsage;
|
|
36
37
|
createHandleUsageCallbacks(copilot: ICopilot, model: string, credentials: any, handleLLMTokens: TChatModelOptions['handleLLMTokens']): {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
name: string;
|
|
39
|
+
lc_serializable: boolean;
|
|
40
|
+
readonly lc_namespace: ["langchain_core", "callbacks", string];
|
|
41
|
+
readonly lc_secrets: {
|
|
42
|
+
[key: string]: string;
|
|
43
|
+
} | undefined;
|
|
44
|
+
readonly lc_attributes: {
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
readonly lc_aliases: {
|
|
48
|
+
[key: string]: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
readonly lc_serializable_keys: string[] | undefined;
|
|
51
|
+
readonly lc_id: string[];
|
|
52
|
+
lc_kwargs: import("@langchain/core/dist/load/map_keys").SerializedFields;
|
|
53
|
+
ignoreLLM: boolean;
|
|
54
|
+
ignoreChain: boolean;
|
|
55
|
+
ignoreAgent: boolean;
|
|
56
|
+
ignoreRetriever: boolean;
|
|
57
|
+
ignoreCustomEvent: boolean;
|
|
58
|
+
raiseError: boolean;
|
|
59
|
+
awaitHandlers: boolean;
|
|
60
|
+
copy(): BaseCallbackHandler;
|
|
61
|
+
toJSON(): import("@langchain/core/load/serializable").Serialized;
|
|
62
|
+
toJSONNotImplemented(): import("@langchain/core/load/serializable").SerializedNotImplemented;
|
|
63
|
+
handleLLMStart?(llm: import("@langchain/core/load/serializable").Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;
|
|
64
|
+
handleLLMNewToken?(token: string, idx: import("@langchain/core/callbacks/base").NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: import("@langchain/core/callbacks/base").HandleLLMNewTokenCallbackFields): Promise<any> | any;
|
|
65
|
+
handleLLMError?(err: any, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;
|
|
66
|
+
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[], extraParams?: Record<string, unknown>): Promise<any> | any;
|
|
67
|
+
handleChatModelStart?(llm: import("@langchain/core/load/serializable").Serialized, messages: import("@langchain/core/messages").BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;
|
|
68
|
+
handleChainStart?(chain: import("@langchain/core/load/serializable").Serialized, inputs: import("@langchain/core/utils/types").ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): Promise<any> | any;
|
|
69
|
+
handleChainError?(err: any, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
70
|
+
inputs?: Record<string, unknown>;
|
|
71
|
+
}): Promise<any> | any;
|
|
72
|
+
handleChainEnd?(outputs: import("@langchain/core/utils/types").ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
73
|
+
inputs?: Record<string, unknown>;
|
|
74
|
+
}): Promise<any> | any;
|
|
75
|
+
handleToolStart?(tool: import("@langchain/core/load/serializable").Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<any> | any;
|
|
76
|
+
handleToolError?(err: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;
|
|
77
|
+
handleToolEnd?(output: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;
|
|
78
|
+
handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
79
|
+
handleAgentAction?(action: import("@langchain/core/dist/agents").AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
80
|
+
handleAgentEnd?(action: import("@langchain/core/dist/agents").AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
81
|
+
handleRetrieverStart?(retriever: import("@langchain/core/load/serializable").Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): Promise<any> | any;
|
|
82
|
+
handleRetrieverEnd?(documents: import("@langchain/core/documents").DocumentInterface[], runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;
|
|
83
|
+
handleRetrieverError?(err: any, runId: string, parentRunId?: string, tags?: string[]): Promise<any> | any;
|
|
84
|
+
handleCustomEvent?(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): Promise<any> | any;
|
|
39
85
|
}[];
|
|
40
86
|
createHandleLLMErrorCallbacks(fields: any, logger?: Logger): {
|
|
41
87
|
handleLLMError: (err: any) => void;
|