@xpert-ai/plugin-sdk 3.16.0 → 3.17.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 +19 -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 +513 -286
- package/index.esm.js +458 -249
- 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 +10 -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
package/index.esm.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Module, Logger, applyDecorators, SetMetadata, HttpException, HttpStatus, BadRequestException, Injectable, Inject, Optional, UnauthorizedException, NotFoundException, ForbiddenException } from '@nestjs/common';
|
|
2
2
|
import { MODULE_METADATA } from '@nestjs/common/constants';
|
|
3
3
|
import { pick } from 'lodash-es';
|
|
4
|
-
import { _ as _extends } from './
|
|
5
|
-
export { b as base64ToBytes, a as bytesToBase64, c as createCollaborationClient, d as createCollaborationPresenceStore, e as createSocketIoTransportAdapter, f as createYjsDocumentAdapter } from './collaboration-client.esm2.js';
|
|
4
|
+
import { _ as _extends } from './_extends.esm.js';
|
|
6
5
|
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
7
6
|
import { Subject, filter } from 'rxjs';
|
|
8
7
|
import { LanguagesEnum, AiModelTypeEnum, ParameterType, PriceType, FetchFrom, ModelFeature, ModelPropertyKey } from '@xpert-ai/contracts';
|
|
@@ -16,8 +15,8 @@ import * as fs from 'fs';
|
|
|
16
15
|
import fs__default from 'fs';
|
|
17
16
|
import http from 'http';
|
|
18
17
|
import https from 'https';
|
|
19
|
-
import {
|
|
20
|
-
|
|
18
|
+
import { c as createRuntimeCapability } from './model-provider.esm.js';
|
|
19
|
+
export { A as ActorTokenRuntimeCapability, a as ArtifactsRuntimeCapability, B as BaseTool, b as BaseToolset, d as BuiltinToolset, D as DefaultAgentMiddlewareRuntimeCapabilityRegistry, D as DefaultRuntimeCapabilityRegistry, K as KnowledgebaseDocumentsRuntimeCapability, e as KnowledgebaseProvisioningRuntimeCapability, f as KnowledgebaseRuntimeCapability, M as ModelProviderBuiltinToolset, S as SANDBOX_JOB_ERROR_CODES, g as SANDBOX_JOB_PROGRESS_PREFIX, h as SandboxJobRuntimeError, i as SandboxJobsRuntimeCapability, W as WORKSPACE_FILES_SOURCE, j as WorkspaceFilesRuntimeCapability, X as XPERT_RUNTIME_CAPABILITIES_TOKEN, k as isSandboxJobRuntimeError } from './model-provider.esm.js';
|
|
21
20
|
import fsPromises from 'fs/promises';
|
|
22
21
|
import * as path from 'path';
|
|
23
22
|
import path__default, { join } from 'path';
|
|
@@ -28,15 +27,21 @@ import yaml__default from 'yaml';
|
|
|
28
27
|
import Ajv from 'ajv';
|
|
29
28
|
import schemaDraft04 from 'ajv/dist/refs/json-schema-draft-06.json';
|
|
30
29
|
import * as _axios from 'axios';
|
|
30
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
31
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
32
|
+
import { isAIMessageChunk, AIMessage } from '@langchain/core/messages';
|
|
31
33
|
import { ChatOpenAICompletions } from '@langchain/openai';
|
|
32
34
|
import { Document } from '@langchain/core/documents';
|
|
33
35
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
34
|
-
import { AIMessage } from '@langchain/core/messages';
|
|
35
36
|
import { getEnvironmentVariable } from '@langchain/core/utils/env';
|
|
37
|
+
export { ModelProviderHttpClient, ModelProviderHttpError } from './model-provider-http-client.esm.js';
|
|
36
38
|
import 'js-tiktoken';
|
|
37
39
|
import { getModelContextSize as getModelContextSize$1 } from '@langchain/core/language_models/base';
|
|
38
40
|
import { assertConnectorDefinition } from './connector.esm.js';
|
|
39
41
|
export { getConnectorAuthMethods } from './connector.esm.js';
|
|
42
|
+
export { base64ToBytes, bytesToBase64, createCollaborationClient, createCollaborationPresenceStore, createSocketIoTransportAdapter, createYjsDocumentAdapter } from './collaboration-client.esm.js';
|
|
43
|
+
import '@langchain/core/tools';
|
|
44
|
+
import 'zod';
|
|
40
45
|
|
|
41
46
|
/**
|
|
42
47
|
* Metadata keys used in plugins for defining various aspects like entities, subscribers, and configurations.
|
|
@@ -944,123 +949,6 @@ ToolsetRegistry = __decorate([
|
|
|
944
949
|
])
|
|
945
950
|
], ToolsetRegistry);
|
|
946
951
|
|
|
947
|
-
/**
|
|
948
|
-
* Base ability for all toolsets
|
|
949
|
-
*/ class BaseToolset extends BaseToolkit {
|
|
950
|
-
/**
|
|
951
|
-
* Async init tools
|
|
952
|
-
*
|
|
953
|
-
* @returns
|
|
954
|
-
*/ async initTools() {
|
|
955
|
-
return this.tools;
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Get one tool
|
|
959
|
-
*
|
|
960
|
-
* @param toolName
|
|
961
|
-
* @returns
|
|
962
|
-
*/ getTool(toolName) {
|
|
963
|
-
var _this_getTools;
|
|
964
|
-
return (_this_getTools = this.getTools()) == null ? void 0 : _this_getTools.find((tool)=>tool.name === toolName);
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Get state variables config
|
|
968
|
-
*
|
|
969
|
-
* @returns State variables
|
|
970
|
-
*/ async getVariables() {
|
|
971
|
-
return null;
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Close all (connections).
|
|
975
|
-
*/ async close() {
|
|
976
|
-
//
|
|
977
|
-
}
|
|
978
|
-
constructor(params){
|
|
979
|
-
super();
|
|
980
|
-
this.params = params;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
class BaseTool extends StructuredTool {
|
|
984
|
-
constructor(...args){
|
|
985
|
-
super(...args);
|
|
986
|
-
this.schema = z.object({
|
|
987
|
-
input: z.string().optional()
|
|
988
|
-
}).transform((obj)=>obj.input);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
class BuiltinToolset extends BaseToolset {
|
|
993
|
-
get tenantId() {
|
|
994
|
-
var _this_params;
|
|
995
|
-
return (_this_params = this.params) == null ? void 0 : _this_params.tenantId;
|
|
996
|
-
}
|
|
997
|
-
get organizationId() {
|
|
998
|
-
var _this_params;
|
|
999
|
-
return (_this_params = this.params) == null ? void 0 : _this_params.organizationId;
|
|
1000
|
-
}
|
|
1001
|
-
get commandBus() {
|
|
1002
|
-
var _this_params;
|
|
1003
|
-
return (_this_params = this.params) == null ? void 0 : _this_params.commandBus;
|
|
1004
|
-
}
|
|
1005
|
-
get queryBus() {
|
|
1006
|
-
var _this_params;
|
|
1007
|
-
return (_this_params = this.params) == null ? void 0 : _this_params.queryBus;
|
|
1008
|
-
}
|
|
1009
|
-
get xpertId() {
|
|
1010
|
-
var _this_params;
|
|
1011
|
-
return (_this_params = this.params) == null ? void 0 : _this_params.xpertId;
|
|
1012
|
-
}
|
|
1013
|
-
async validateCredentials(credentials) {
|
|
1014
|
-
await this._validateCredentials(credentials);
|
|
1015
|
-
}
|
|
1016
|
-
async _validateCredentials(credentials) {
|
|
1017
|
-
throw new Error('Method not implemented.');
|
|
1018
|
-
}
|
|
1019
|
-
getId() {
|
|
1020
|
-
var _this_toolset;
|
|
1021
|
-
return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.id;
|
|
1022
|
-
}
|
|
1023
|
-
getCredentials() {
|
|
1024
|
-
var _this_toolset;
|
|
1025
|
-
return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.credentials;
|
|
1026
|
-
}
|
|
1027
|
-
getToolTitle(name) {
|
|
1028
|
-
var _this_toolset_tools, _this_toolset, _tool_schema;
|
|
1029
|
-
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);
|
|
1030
|
-
const identity = tool == null ? void 0 : (_tool_schema = tool.schema) == null ? void 0 : _tool_schema.identity;
|
|
1031
|
-
if (identity) {
|
|
1032
|
-
return identity.label;
|
|
1033
|
-
}
|
|
1034
|
-
return null;
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Get credentials schema
|
|
1038
|
-
*
|
|
1039
|
-
* @returns Credentials schema
|
|
1040
|
-
*/ getCredentialsSchema() {
|
|
1041
|
-
return _extends({}, this.credentialsSchema);
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Get toolset entity
|
|
1045
|
-
*
|
|
1046
|
-
* @returns XpertToolset
|
|
1047
|
-
*/ getToolset() {
|
|
1048
|
-
return this.toolset;
|
|
1049
|
-
}
|
|
1050
|
-
getName() {
|
|
1051
|
-
var _this_getToolset;
|
|
1052
|
-
return (_this_getToolset = this.getToolset()) == null ? void 0 : _this_getToolset.name;
|
|
1053
|
-
}
|
|
1054
|
-
constructor(providerName, toolset, params){
|
|
1055
|
-
super(params);
|
|
1056
|
-
this.logger = new Logger(this.constructor.name);
|
|
1057
|
-
this.providerName = providerName;
|
|
1058
|
-
this.toolset = toolset;
|
|
1059
|
-
this.params = params;
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
BuiltinToolset.provider = '';
|
|
1063
|
-
|
|
1064
952
|
/**
|
|
1065
953
|
* Restricted FileSystem based on granted permissions
|
|
1066
954
|
*/ class XpFileSystem {
|
|
@@ -1415,40 +1303,6 @@ PluginWebhookAuthGuard = __decorate([
|
|
|
1415
1303
|
])
|
|
1416
1304
|
], PluginWebhookAuthGuard);
|
|
1417
1305
|
|
|
1418
|
-
function createRuntimeCapability(id, options = {}) {
|
|
1419
|
-
return Object.freeze({
|
|
1420
|
-
id,
|
|
1421
|
-
description: options.description
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
const XPERT_RUNTIME_CAPABILITIES_TOKEN = 'XPERT_RUNTIME_CAPABILITIES';
|
|
1425
|
-
class DefaultRuntimeCapabilityRegistry {
|
|
1426
|
-
register(key, implementation) {
|
|
1427
|
-
this.capabilities.set(runtimeCapabilityId(key), implementation);
|
|
1428
|
-
return this;
|
|
1429
|
-
}
|
|
1430
|
-
has(key) {
|
|
1431
|
-
return this.capabilities.has(runtimeCapabilityId(key));
|
|
1432
|
-
}
|
|
1433
|
-
get(key) {
|
|
1434
|
-
return this.capabilities.get(runtimeCapabilityId(key));
|
|
1435
|
-
}
|
|
1436
|
-
require(key) {
|
|
1437
|
-
const implementation = this.get(key);
|
|
1438
|
-
if (!implementation) {
|
|
1439
|
-
throw new Error(`Runtime capability '${runtimeCapabilityId(key)}' is not available`);
|
|
1440
|
-
}
|
|
1441
|
-
return implementation;
|
|
1442
|
-
}
|
|
1443
|
-
constructor(entries = []){
|
|
1444
|
-
this.capabilities = new Map();
|
|
1445
|
-
entries.forEach(([key, implementation])=>this.register(key, implementation));
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
function runtimeCapabilityId(key) {
|
|
1449
|
-
return typeof key === 'string' ? key : key.id;
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
1306
|
const DATASOURCE_STRATEGY = 'DATASOURCE_STRATEGY';
|
|
1453
1307
|
const DataSourceStrategy = (provider)=>applyDecorators(SetMetadata(DATASOURCE_STRATEGY, provider), SetMetadata(STRATEGY_META_KEY, DATASOURCE_STRATEGY));
|
|
1454
1308
|
|
|
@@ -1834,10 +1688,15 @@ let ModelProvider = ModelProvider_1 = class ModelProvider {
|
|
|
1834
1688
|
}
|
|
1835
1689
|
async getModels(modelType) {
|
|
1836
1690
|
const providerSchema = this.getProviderSchema();
|
|
1837
|
-
|
|
1691
|
+
const supported = providerSchema.supported_model_types.includes(modelType) || modelType === AiModelTypeEnum.IMAGE && providerSchema.supported_model_types.includes(AiModelTypeEnum.TEXT2IMG);
|
|
1692
|
+
if (!supported) {
|
|
1838
1693
|
return [];
|
|
1839
1694
|
}
|
|
1840
|
-
|
|
1695
|
+
var _this_modelManagers_get;
|
|
1696
|
+
const modelInstance = modelType === AiModelTypeEnum.IMAGE ? (_this_modelManagers_get = this.modelManagers.get(AiModelTypeEnum.IMAGE)) != null ? _this_modelManagers_get : this.modelManagers.get(AiModelTypeEnum.TEXT2IMG) : this.modelManagers.get(modelType);
|
|
1697
|
+
if (!modelInstance) {
|
|
1698
|
+
throw new AiModelNotFoundException(`Missing AIModel instance for model type ${modelType}`);
|
|
1699
|
+
}
|
|
1841
1700
|
return modelInstance.predefinedModels();
|
|
1842
1701
|
}
|
|
1843
1702
|
registerAIModelInstance(modelType, modelInstance) {
|
|
@@ -1869,7 +1728,8 @@ let ModelProvider = ModelProvider_1 = class ModelProvider {
|
|
|
1869
1728
|
getSystemProviderModels(modelTypes) {
|
|
1870
1729
|
const models = [];
|
|
1871
1730
|
modelTypes == null ? void 0 : modelTypes.forEach((modelType)=>{
|
|
1872
|
-
|
|
1731
|
+
var _this_modelManagers_get;
|
|
1732
|
+
const modelManager = modelType === AiModelTypeEnum.IMAGE ? (_this_modelManagers_get = this.modelManagers.get(AiModelTypeEnum.IMAGE)) != null ? _this_modelManagers_get : this.modelManagers.get(AiModelTypeEnum.TEXT2IMG) : this.modelManagers.get(modelType);
|
|
1873
1733
|
if (modelManager) {
|
|
1874
1734
|
models.push(...modelManager.predefinedModels());
|
|
1875
1735
|
}
|
|
@@ -1903,6 +1763,14 @@ let ModelProvider = ModelProvider_1 = class ModelProvider {
|
|
|
1903
1763
|
case AiModelTypeEnum.RERANK:
|
|
1904
1764
|
var _this_getModelManager4;
|
|
1905
1765
|
return (_this_getModelManager4 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager4.getReranker(copilotModel, options);
|
|
1766
|
+
case AiModelTypeEnum.IMAGE:
|
|
1767
|
+
var _this;
|
|
1768
|
+
var _this_modelManagers_get;
|
|
1769
|
+
return (_this = (_this_modelManagers_get = this.modelManagers.get(AiModelTypeEnum.IMAGE)) != null ? _this_modelManagers_get : this.modelManagers.get(AiModelTypeEnum.TEXT2IMG)) == null ? void 0 : _this.getAIGCModel(copilotModel, options);
|
|
1770
|
+
case AiModelTypeEnum.TEXT2IMG:
|
|
1771
|
+
case AiModelTypeEnum.VIDEO:
|
|
1772
|
+
var _this_getModelManager5;
|
|
1773
|
+
return (_this_getModelManager5 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager5.getAIGCModel(copilotModel, options);
|
|
1906
1774
|
}
|
|
1907
1775
|
return null;
|
|
1908
1776
|
}
|
|
@@ -2128,15 +1996,137 @@ function calculateModelPrice(pricing, priceType, tokens, inputTokens = tokens) {
|
|
|
2128
1996
|
currency: pricing.currency
|
|
2129
1997
|
};
|
|
2130
1998
|
}
|
|
1999
|
+
function resolveModelUsagePricingSnapshot(pricing, context) {
|
|
2000
|
+
var _normalizeDate;
|
|
2001
|
+
var _normalizeDate_toISOString;
|
|
2002
|
+
const capturedAt = (_normalizeDate_toISOString = (_normalizeDate = normalizeDate(context.startedAt)) == null ? void 0 : _normalizeDate.toISOString()) != null ? _normalizeDate_toISOString : new Date().toISOString();
|
|
2003
|
+
if (!isModelUsagePricingConfig(pricing)) {
|
|
2004
|
+
return {
|
|
2005
|
+
capturedAt,
|
|
2006
|
+
rules: []
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
const at = new Date(capturedAt);
|
|
2010
|
+
const rules = pricing.rules.filter((rule)=>matchesUsagePriceRule(rule, context, at));
|
|
2011
|
+
const units = new Set();
|
|
2012
|
+
for (const rule of rules){
|
|
2013
|
+
validateUsagePriceRule(rule);
|
|
2014
|
+
if (units.has(rule.unit)) {
|
|
2015
|
+
throw new Error(`Ambiguous usage pricing rules for unit '${rule.unit}'`);
|
|
2016
|
+
}
|
|
2017
|
+
units.add(rule.unit);
|
|
2018
|
+
}
|
|
2019
|
+
return {
|
|
2020
|
+
capturedAt,
|
|
2021
|
+
rules
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
function calculateModelUsageCharge(snapshot, metric) {
|
|
2025
|
+
const rule = snapshot == null ? void 0 : snapshot.rules.find((candidate)=>candidate.unit === metric.unit);
|
|
2026
|
+
const fallbackQuantity = metricQuantity(metric);
|
|
2027
|
+
if (!rule) {
|
|
2028
|
+
return {
|
|
2029
|
+
pricingStatus: 'unpriced',
|
|
2030
|
+
quantity: fallbackQuantity
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
const quantity = rule.unit === 'token' ? tokenQuantity(metric, rule.token_type) : fallbackQuantity;
|
|
2034
|
+
if (rule.charge_type === 'free') {
|
|
2035
|
+
return _extends({
|
|
2036
|
+
pricingStatus: 'free',
|
|
2037
|
+
pricingRule: rule,
|
|
2038
|
+
quantity,
|
|
2039
|
+
unitSize: rule.unit_size,
|
|
2040
|
+
unitPrice: 0
|
|
2041
|
+
}, rule.currency ? {
|
|
2042
|
+
currency: rule.currency
|
|
2043
|
+
} : {}, {
|
|
2044
|
+
amount: 0
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
const unitPrice = Number(rule.unit_price);
|
|
2048
|
+
const unitSize = Number(rule.unit_size);
|
|
2049
|
+
return {
|
|
2050
|
+
pricingStatus: 'priced',
|
|
2051
|
+
pricingRule: rule,
|
|
2052
|
+
quantity,
|
|
2053
|
+
unitSize,
|
|
2054
|
+
unitPrice,
|
|
2055
|
+
currency: rule.currency,
|
|
2056
|
+
amount: roundCharge(quantity / unitSize * unitPrice)
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
function isModelUsagePricingConfig(pricing) {
|
|
2060
|
+
return pricing !== undefined && 'type' in pricing && pricing.type === 'usage' && Array.isArray(pricing.rules);
|
|
2061
|
+
}
|
|
2062
|
+
function matchesUsagePriceRule(rule, context, at) {
|
|
2063
|
+
var _rule_operations;
|
|
2064
|
+
const effectiveFrom = normalizeDate(rule.effective_from);
|
|
2065
|
+
const effectiveTo = normalizeDate(rule.effective_to);
|
|
2066
|
+
if (!effectiveFrom || effectiveFrom > at || effectiveTo && effectiveTo <= at) return false;
|
|
2067
|
+
if (((_rule_operations = rule.operations) == null ? void 0 : _rule_operations.length) && !rule.operations.includes(context.operation)) return false;
|
|
2068
|
+
var _context_pricingDimensions;
|
|
2069
|
+
const dimensions = (_context_pricingDimensions = context.pricingDimensions) != null ? _context_pricingDimensions : {};
|
|
2070
|
+
var _rule_dimensions;
|
|
2071
|
+
return Object.entries((_rule_dimensions = rule.dimensions) != null ? _rule_dimensions : {}).every(([key, value])=>{
|
|
2072
|
+
if (key === 'resolution') return dimensions.resolution === value;
|
|
2073
|
+
if (key === 'audio') return dimensions.audio === value;
|
|
2074
|
+
if (key === 'videoInput') return dimensions.videoInput === value;
|
|
2075
|
+
if (key === 'mode') return dimensions.mode === value;
|
|
2076
|
+
return false;
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
function validateUsagePriceRule(rule) {
|
|
2080
|
+
var _rule_id, _rule_version;
|
|
2081
|
+
if (!((_rule_id = rule.id) == null ? void 0 : _rule_id.trim()) || !((_rule_version = rule.version) == null ? void 0 : _rule_version.trim())) throw new Error('Usage pricing rules require id and version');
|
|
2082
|
+
if (!Number.isFinite(Number(rule.unit_size)) || Number(rule.unit_size) <= 0) {
|
|
2083
|
+
throw new Error(`Usage pricing rule '${rule.id}' requires a positive unit_size`);
|
|
2084
|
+
}
|
|
2085
|
+
if (rule.unit !== 'token' && rule.token_type) {
|
|
2086
|
+
throw new Error(`Usage pricing rule '${rule.id}' can only use token_type with token pricing`);
|
|
2087
|
+
}
|
|
2088
|
+
if (rule.charge_type === 'paid') {
|
|
2089
|
+
var _rule_currency;
|
|
2090
|
+
if (!Number.isFinite(Number(rule.unit_price)) || Number(rule.unit_price) <= 0 || !((_rule_currency = rule.currency) == null ? void 0 : _rule_currency.trim())) {
|
|
2091
|
+
throw new Error(`Paid usage pricing rule '${rule.id}' requires unit_price and currency`);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
function metricQuantity(metric) {
|
|
2096
|
+
if (metric.unit !== 'token') return finiteQuantity(metric.quantity);
|
|
2097
|
+
var _metric_totalTokens, _ref;
|
|
2098
|
+
return finiteQuantity((_ref = (_metric_totalTokens = metric.totalTokens) != null ? _metric_totalTokens : metric.promptTokens) != null ? _ref : metric.completionTokens);
|
|
2099
|
+
}
|
|
2100
|
+
function tokenQuantity(metric, tokenType) {
|
|
2101
|
+
if (metric.unit !== 'token') return 0;
|
|
2102
|
+
if (tokenType === 'prompt') return finiteQuantity(metric.promptTokens);
|
|
2103
|
+
if (tokenType === 'completion') return finiteQuantity(metric.completionTokens);
|
|
2104
|
+
return finiteQuantity(metric.totalTokens);
|
|
2105
|
+
}
|
|
2106
|
+
function finiteQuantity(value) {
|
|
2107
|
+
const quantity = Number(value);
|
|
2108
|
+
return Number.isFinite(quantity) && quantity > 0 ? quantity : 0;
|
|
2109
|
+
}
|
|
2110
|
+
function normalizeDate(value) {
|
|
2111
|
+
if (!value) return undefined;
|
|
2112
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
2113
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
2114
|
+
}
|
|
2115
|
+
function roundCharge(value) {
|
|
2116
|
+
return Number(value.toFixed(10));
|
|
2117
|
+
}
|
|
2131
2118
|
|
|
2132
2119
|
var AIModel_1;
|
|
2133
2120
|
let AIModel = AIModel_1 = class AIModel {
|
|
2134
2121
|
getChatModel(copilotModel, options) {
|
|
2135
2122
|
throw new Error(`Unsupport chat model!`);
|
|
2136
2123
|
}
|
|
2124
|
+
getAIGCModel(copilotModel, options) {
|
|
2125
|
+
throw new Error(`Unsupported AIGC model!`);
|
|
2126
|
+
}
|
|
2137
2127
|
getPrice(model, credentials, priceType, tokens, inputTokens = tokens) {
|
|
2138
2128
|
const modelSchema = this.getModelSchema(model, credentials);
|
|
2139
|
-
if (!modelSchema || !modelSchema.pricing) {
|
|
2129
|
+
if (!modelSchema || !modelSchema.pricing || isModelUsagePricingConfig(modelSchema.pricing)) {
|
|
2140
2130
|
return {
|
|
2141
2131
|
unitPrice: 0,
|
|
2142
2132
|
unit: 0,
|
|
@@ -2146,6 +2136,10 @@ let AIModel = AIModel_1 = class AIModel {
|
|
|
2146
2136
|
}
|
|
2147
2137
|
return calculateModelPrice(modelSchema.pricing, priceType, tokens, inputTokens);
|
|
2148
2138
|
}
|
|
2139
|
+
getUsagePricingSnapshot(model, credentials, context) {
|
|
2140
|
+
var _this_getModelSchema;
|
|
2141
|
+
return resolveModelUsagePricingSnapshot((_this_getModelSchema = this.getModelSchema(model, credentials)) == null ? void 0 : _this_getModelSchema.pricing, context);
|
|
2142
|
+
}
|
|
2149
2143
|
getModelPath() {
|
|
2150
2144
|
const modelType = this.modelType.toLowerCase();
|
|
2151
2145
|
return path.join(this.modelProvider.getProviderServerPath(), modelType);
|
|
@@ -2335,6 +2329,11 @@ class TextToSpeechModel extends AIModel {
|
|
|
2335
2329
|
}
|
|
2336
2330
|
}
|
|
2337
2331
|
|
|
2332
|
+
class ImageGenerationModel extends AIModel {
|
|
2333
|
+
}
|
|
2334
|
+
class VideoGenerationModel extends AIModel {
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2338
2337
|
const PROVIDE_AI_MODEL_LLM = 'provide_ai_model_llm';
|
|
2339
2338
|
const PROVIDE_AI_MODEL_MODERATION = 'provide_ai_model_moderation';
|
|
2340
2339
|
const PROVIDE_AI_MODEL_SPEECH2TEXT = 'provide_ai_model_speech2text';
|
|
@@ -2399,7 +2398,7 @@ class LargeLanguageModel extends AIModel {
|
|
|
2399
2398
|
_commonParameterRules(model) {
|
|
2400
2399
|
return CommonParameterRules;
|
|
2401
2400
|
}
|
|
2402
|
-
calcResponseUsage(model, credentials, promptTokens, completionTokens) {
|
|
2401
|
+
calcResponseUsage(model, credentials, promptTokens, completionTokens, startedAt = this.startedAt) {
|
|
2403
2402
|
const promptPriceInfo = this.getPrice(model, credentials, PriceType.INPUT, promptTokens, promptTokens);
|
|
2404
2403
|
const completionPriceInfo = this.getPrice(model, credentials, PriceType.OUTPUT, completionTokens, promptTokens);
|
|
2405
2404
|
const totalPrice = Number((promptPriceInfo.totalAmount + completionPriceInfo.totalAmount).toFixed(7));
|
|
@@ -2416,30 +2415,68 @@ class LargeLanguageModel extends AIModel {
|
|
|
2416
2415
|
totalTokens: promptTokens + completionTokens,
|
|
2417
2416
|
totalPrice,
|
|
2418
2417
|
currency: promptPriceInfo.currency,
|
|
2419
|
-
latency: performance.now() -
|
|
2418
|
+
latency: performance.now() - startedAt
|
|
2420
2419
|
};
|
|
2421
2420
|
return usage;
|
|
2422
2421
|
}
|
|
2423
2422
|
createHandleUsageCallbacks(copilot, model, credentials, handleLLMTokens) {
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2423
|
+
const runs = new Map();
|
|
2424
|
+
const reportUsage = async (requestId, tokenUsage, startedAt, type)=>{
|
|
2425
|
+
if (!handleLLMTokens || tokenUsage.totalTokens <= 0) {
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
const usage = _extends({}, this.calcResponseUsage(model, credentials, tokenUsage.promptTokens, tokenUsage.completionTokens, startedAt), type ? {
|
|
2429
|
+
type
|
|
2430
|
+
} : {});
|
|
2431
|
+
usage.totalTokens = tokenUsage.totalTokens;
|
|
2432
|
+
await handleLLMTokens({
|
|
2433
|
+
copilot,
|
|
2434
|
+
model,
|
|
2435
|
+
requestId,
|
|
2436
|
+
usage,
|
|
2437
|
+
tokenUsed: tokenUsage.totalTokens
|
|
2438
|
+
});
|
|
2439
|
+
};
|
|
2440
|
+
const callback = BaseCallbackHandler.fromMethods({
|
|
2441
|
+
handleLLMStart: (_llm, prompts, runId)=>{
|
|
2442
|
+
runs.set(runId, {
|
|
2443
|
+
startedAt: performance.now(),
|
|
2444
|
+
prompts,
|
|
2445
|
+
completion: ''
|
|
2446
|
+
});
|
|
2447
|
+
},
|
|
2448
|
+
handleLLMNewToken: (token, _idx, runId, _parentRunId, _tags, fields)=>{
|
|
2449
|
+
const run = runs.get(runId);
|
|
2450
|
+
if (run) {
|
|
2451
|
+
run.completion += token + readToolCallChunkText(fields == null ? void 0 : fields.chunk);
|
|
2441
2452
|
}
|
|
2453
|
+
},
|
|
2454
|
+
handleLLMEnd: async (output, runId)=>{
|
|
2455
|
+
const run = runs.get(runId);
|
|
2456
|
+
runs.delete(runId);
|
|
2457
|
+
const resolved = resolveTokenUsageWithAuthority(output);
|
|
2458
|
+
if (resolved.usage.totalTokens > 0) {
|
|
2459
|
+
var _run_startedAt;
|
|
2460
|
+
await reportUsage(runId, resolved.usage, (_run_startedAt = run == null ? void 0 : run.startedAt) != null ? _run_startedAt : performance.now(), resolved.type);
|
|
2461
|
+
} else {
|
|
2462
|
+
var _run_startedAt1;
|
|
2463
|
+
await reportUsage(runId, estimateFallbackUsage(run == null ? void 0 : run.prompts, (run == null ? void 0 : run.completion) || readCompletionText(output)), (_run_startedAt1 = run == null ? void 0 : run.startedAt) != null ? _run_startedAt1 : performance.now(), 'estimated');
|
|
2464
|
+
}
|
|
2465
|
+
},
|
|
2466
|
+
handleLLMError: async (error, runId)=>{
|
|
2467
|
+
const run = runs.get(runId);
|
|
2468
|
+
runs.delete(runId);
|
|
2469
|
+
if (!(run == null ? void 0 : run.completion) && !isAbortError(error)) {
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
var _run_startedAt;
|
|
2473
|
+
await reportUsage(runId, estimateFallbackUsage(run == null ? void 0 : run.prompts, run == null ? void 0 : run.completion), (_run_startedAt = run == null ? void 0 : run.startedAt) != null ? _run_startedAt : performance.now(), 'estimated');
|
|
2442
2474
|
}
|
|
2475
|
+
});
|
|
2476
|
+
callback.awaitHandlers = true;
|
|
2477
|
+
callback.raiseError = true;
|
|
2478
|
+
return [
|
|
2479
|
+
callback
|
|
2443
2480
|
];
|
|
2444
2481
|
}
|
|
2445
2482
|
createHandleLLMErrorCallbacks(fields, logger) {
|
|
@@ -2576,6 +2613,55 @@ class LargeLanguageModel extends AIModel {
|
|
|
2576
2613
|
}
|
|
2577
2614
|
}
|
|
2578
2615
|
_a = LargeLanguageModel;
|
|
2616
|
+
function estimateFallbackUsage(prompts, completion) {
|
|
2617
|
+
if (!prompts) {
|
|
2618
|
+
return {
|
|
2619
|
+
promptTokens: 0,
|
|
2620
|
+
completionTokens: 0,
|
|
2621
|
+
totalTokens: 0
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
const promptTokens = estimateTokens(prompts.join('\n'));
|
|
2625
|
+
const completionTokens = estimateTokens(completion != null ? completion : '');
|
|
2626
|
+
return {
|
|
2627
|
+
promptTokens,
|
|
2628
|
+
completionTokens,
|
|
2629
|
+
totalTokens: promptTokens + completionTokens
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
function readCompletionText(output) {
|
|
2633
|
+
var _output_generations;
|
|
2634
|
+
return (_output_generations = output.generations) == null ? void 0 : _output_generations.flat().map((generation)=>generation.text).filter(Boolean).join('\n');
|
|
2635
|
+
}
|
|
2636
|
+
function estimateTokens(text) {
|
|
2637
|
+
const estimatedText = text.replace(/data:image\/[a-zA-Z0-9.+-]+;base64,[a-zA-Z0-9+/_=-]+/g, '[image]');
|
|
2638
|
+
let cjkCharacters = 0;
|
|
2639
|
+
let otherCharacters = 0;
|
|
2640
|
+
for (const character of estimatedText){
|
|
2641
|
+
if (RegExp("\\p{Script=Han}", "u").test(character)) {
|
|
2642
|
+
cjkCharacters++;
|
|
2643
|
+
} else {
|
|
2644
|
+
otherCharacters++;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
return Math.ceil(cjkCharacters / 1.5 + otherCharacters / 4);
|
|
2648
|
+
}
|
|
2649
|
+
function readToolCallChunkText(chunk) {
|
|
2650
|
+
if (!(chunk instanceof ChatGenerationChunk) || !isAIMessageChunk(chunk.message)) {
|
|
2651
|
+
return '';
|
|
2652
|
+
}
|
|
2653
|
+
var _chunk_message_tool_call_chunks;
|
|
2654
|
+
return ((_chunk_message_tool_call_chunks = chunk.message.tool_call_chunks) != null ? _chunk_message_tool_call_chunks : []).map((toolCall)=>{
|
|
2655
|
+
var _toolCall_name, _toolCall_args;
|
|
2656
|
+
return `${(_toolCall_name = toolCall.name) != null ? _toolCall_name : ''}${(_toolCall_args = toolCall.args) != null ? _toolCall_args : ''}`;
|
|
2657
|
+
}).join('');
|
|
2658
|
+
}
|
|
2659
|
+
function isAbortError(error) {
|
|
2660
|
+
if (!(error instanceof Error)) {
|
|
2661
|
+
return false;
|
|
2662
|
+
}
|
|
2663
|
+
return error.name === 'AbortError' || /\babort(?:ed)?\b/i.test(error.message);
|
|
2664
|
+
}
|
|
2579
2665
|
function calcTokenUsage(output) {
|
|
2580
2666
|
var _output_generations;
|
|
2581
2667
|
const tokenUsage = {
|
|
@@ -2596,14 +2682,32 @@ function calcTokenUsage(output) {
|
|
|
2596
2682
|
return tokenUsage;
|
|
2597
2683
|
}
|
|
2598
2684
|
function resolveTokenUsage(output) {
|
|
2685
|
+
return resolveTokenUsageWithAuthority(output).usage;
|
|
2686
|
+
}
|
|
2687
|
+
function resolveTokenUsageWithAuthority(output) {
|
|
2599
2688
|
var _output_llmOutput, _output_llmOutput1, _output_llmOutput2;
|
|
2600
|
-
var _normalizeTokenUsage, _ref
|
|
2601
|
-
|
|
2602
|
-
totalTokens: (
|
|
2603
|
-
})
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2689
|
+
var _normalizeTokenUsage, _ref;
|
|
2690
|
+
const actualUsage = (_ref = (_normalizeTokenUsage = normalizeTokenUsage(calcTokenUsage(output))) != null ? _normalizeTokenUsage : normalizeTokenUsage((_output_llmOutput = output.llmOutput) == null ? void 0 : _output_llmOutput['tokenUsage'])) != null ? _ref : normalizeTokenUsage({
|
|
2691
|
+
totalTokens: (_output_llmOutput1 = output.llmOutput) == null ? void 0 : _output_llmOutput1['totalTokens']
|
|
2692
|
+
});
|
|
2693
|
+
if (actualUsage) {
|
|
2694
|
+
return {
|
|
2695
|
+
usage: actualUsage
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
const estimatedUsage = normalizeTokenUsage((_output_llmOutput2 = output.llmOutput) == null ? void 0 : _output_llmOutput2['estimatedTokenUsage']);
|
|
2699
|
+
if (estimatedUsage) {
|
|
2700
|
+
return {
|
|
2701
|
+
usage: estimatedUsage,
|
|
2702
|
+
type: 'estimated'
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
return {
|
|
2706
|
+
usage: {
|
|
2707
|
+
promptTokens: 0,
|
|
2708
|
+
completionTokens: 0,
|
|
2709
|
+
totalTokens: 0
|
|
2710
|
+
}
|
|
2607
2711
|
};
|
|
2608
2712
|
}
|
|
2609
2713
|
function normalizeTokenUsage(candidate) {
|
|
@@ -2646,6 +2750,109 @@ function isValidTokenCount(value) {
|
|
|
2646
2750
|
return tokenUsed;
|
|
2647
2751
|
}
|
|
2648
2752
|
|
|
2753
|
+
/**
|
|
2754
|
+
* Runs one asynchronous provider request inside a Managed Queue job.
|
|
2755
|
+
* Provider acceptance, terminal usage reporting, and result delivery are checkpointed so a queue retry resumes
|
|
2756
|
+
* from the last durable provider request instead of intentionally submitting a second request.
|
|
2757
|
+
*/ async function processAsyncAIGCManagedJob(job, options) {
|
|
2758
|
+
let payload = job.data;
|
|
2759
|
+
if (payload.phase === 'succeeded' && payload.result !== undefined) return payload.result;
|
|
2760
|
+
if (payload.phase === 'failed') throw new Error(payload.errorCode || 'Provider generation task failed');
|
|
2761
|
+
if (!payload.pricingSnapshot) {
|
|
2762
|
+
const pricingSnapshot = options.provider.resolvePricingSnapshot ? await options.provider.resolvePricingSnapshot({
|
|
2763
|
+
model: payload.model,
|
|
2764
|
+
operation: payload.operation,
|
|
2765
|
+
modality: payload.modality,
|
|
2766
|
+
pricingDimensions: payload.pricingDimensions,
|
|
2767
|
+
startedAt: payload.startedAt
|
|
2768
|
+
}) : {
|
|
2769
|
+
capturedAt: new Date().toISOString(),
|
|
2770
|
+
rules: []
|
|
2771
|
+
};
|
|
2772
|
+
payload = await checkpoint(job, _extends({}, payload, {
|
|
2773
|
+
pricingSnapshot
|
|
2774
|
+
}));
|
|
2775
|
+
}
|
|
2776
|
+
if (!payload.providerRequestId) {
|
|
2777
|
+
const submission = await options.client.submit(payload.input);
|
|
2778
|
+
payload = await checkpoint(job, _extends({}, payload, {
|
|
2779
|
+
providerRequestId: submission.providerRequestId,
|
|
2780
|
+
phase: 'submitted',
|
|
2781
|
+
providerState: 'submitted'
|
|
2782
|
+
}));
|
|
2783
|
+
}
|
|
2784
|
+
const providerRequestId = payload.providerRequestId;
|
|
2785
|
+
var _options_sleep;
|
|
2786
|
+
const sleep = (_options_sleep = options.sleep) != null ? _options_sleep : delay;
|
|
2787
|
+
const pollIntervalMs = normalizePollInterval(options.pollIntervalMs);
|
|
2788
|
+
while(true){
|
|
2789
|
+
const query = await options.client.query(providerRequestId, {
|
|
2790
|
+
operation: payload.operation,
|
|
2791
|
+
pricingDimensions: payload.pricingDimensions
|
|
2792
|
+
});
|
|
2793
|
+
const observation = query.observation;
|
|
2794
|
+
payload = await checkpoint(job, _extends({}, payload, {
|
|
2795
|
+
providerState: observation.state,
|
|
2796
|
+
phase: toJobPhase(observation.state)
|
|
2797
|
+
}, observation.errorCode ? {
|
|
2798
|
+
errorCode: observation.errorCode
|
|
2799
|
+
} : {}));
|
|
2800
|
+
if (observation.state === 'succeeded') {
|
|
2801
|
+
payload = await reportTerminalUsage(job, payload, observation.metrics, options.provider);
|
|
2802
|
+
const result = await options.finalize(query.data);
|
|
2803
|
+
payload = await checkpoint(job, _extends({}, payload, {
|
|
2804
|
+
phase: 'succeeded',
|
|
2805
|
+
result
|
|
2806
|
+
}));
|
|
2807
|
+
return result;
|
|
2808
|
+
}
|
|
2809
|
+
if (observation.state === 'failed' || observation.state === 'cancelled') {
|
|
2810
|
+
payload = await reportTerminalUsage(job, payload, observation.metrics, options.provider);
|
|
2811
|
+
var _options_failureMessage, _ref;
|
|
2812
|
+
const message = (_ref = (_options_failureMessage = options.failureMessage == null ? void 0 : options.failureMessage.call(options, query.data, observation)) != null ? _options_failureMessage : observation.errorCode) != null ? _ref : `Provider generation task ${providerRequestId} ${observation.state}`;
|
|
2813
|
+
await checkpoint(job, _extends({}, payload, {
|
|
2814
|
+
phase: 'failed',
|
|
2815
|
+
errorCode: message
|
|
2816
|
+
}));
|
|
2817
|
+
throw new Error(message);
|
|
2818
|
+
}
|
|
2819
|
+
await sleep(pollIntervalMs);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
async function reportTerminalUsage(job, payload, metrics, provider) {
|
|
2823
|
+
if (payload.usageReported || !(metrics == null ? void 0 : metrics.length)) return payload;
|
|
2824
|
+
await provider.reportUsage({
|
|
2825
|
+
requestId: payload.requestId,
|
|
2826
|
+
model: payload.model,
|
|
2827
|
+
modelType: payload.modality === 'image' ? AiModelTypeEnum.IMAGE : AiModelTypeEnum.VIDEO,
|
|
2828
|
+
toolName: payload.toolName,
|
|
2829
|
+
operation: payload.operation,
|
|
2830
|
+
modality: payload.modality,
|
|
2831
|
+
pricingDimensions: payload.pricingDimensions,
|
|
2832
|
+
pricingSnapshot: payload.pricingSnapshot,
|
|
2833
|
+
metrics,
|
|
2834
|
+
recordedAt: new Date().toISOString()
|
|
2835
|
+
});
|
|
2836
|
+
return checkpoint(job, _extends({}, payload, {
|
|
2837
|
+
usageReported: true
|
|
2838
|
+
}));
|
|
2839
|
+
}
|
|
2840
|
+
async function checkpoint(job, payload) {
|
|
2841
|
+
await job.updateData(payload);
|
|
2842
|
+
return payload;
|
|
2843
|
+
}
|
|
2844
|
+
function toJobPhase(state) {
|
|
2845
|
+
if (state === 'succeeded') return 'succeeded';
|
|
2846
|
+
if (state === 'failed' || state === 'cancelled') return 'failed';
|
|
2847
|
+
return state === 'submitted' ? 'submitted' : 'processing';
|
|
2848
|
+
}
|
|
2849
|
+
function normalizePollInterval(value) {
|
|
2850
|
+
return Number.isFinite(value) && Number(value) > 0 ? Math.trunc(Number(value)) : 5000;
|
|
2851
|
+
}
|
|
2852
|
+
function delay(milliseconds) {
|
|
2853
|
+
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2649
2856
|
/**
|
|
2650
2857
|
* A model extended from ChatOpenAICompletions, compatible with OpenAI-style chat completions,
|
|
2651
2858
|
* and supports structuring content within `<think>` reasoning tags into the `reasoning_content` field.
|
|
@@ -2661,7 +2868,12 @@ function isValidTokenCount(value) {
|
|
|
2661
2868
|
*
|
|
2662
2869
|
*/ _convertCompletionsDeltaToBaseMessageChunk(// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2663
2870
|
delta, rawResponse, defaultRole) {
|
|
2664
|
-
|
|
2871
|
+
// Some OpenAI-compatible providers omit `delta.role` on the final usage
|
|
2872
|
+
// chunk. Without a role, LangChain creates a generic ChatMessageChunk;
|
|
2873
|
+
// persisting that chunk makes the next request contain `role: undefined`.
|
|
2874
|
+
// Treat role-less completion deltas as assistant output so they remain
|
|
2875
|
+
// valid both in the current stream and when the conversation is resumed.
|
|
2876
|
+
const messageChunk = super._convertCompletionsDeltaToBaseMessageChunk(delta, rawResponse, defaultRole != null ? defaultRole : 'assistant');
|
|
2665
2877
|
if (delta['content'] === '<think>') {
|
|
2666
2878
|
this.thinking = true;
|
|
2667
2879
|
messageChunk.content = '';
|
|
@@ -2677,7 +2889,14 @@ function isValidTokenCount(value) {
|
|
|
2677
2889
|
return messageChunk;
|
|
2678
2890
|
}
|
|
2679
2891
|
_convertCompletionsMessageToBaseMessage(message, rawResponse) {
|
|
2680
|
-
|
|
2892
|
+
var _message_role;
|
|
2893
|
+
// Some compatible providers also omit the role on non-stream responses.
|
|
2894
|
+
// Normalize that response before LangChain falls back to a generic
|
|
2895
|
+
// message with role `unknown`.
|
|
2896
|
+
const normalizedMessage = _extends({}, message, {
|
|
2897
|
+
role: (_message_role = message.role) != null ? _message_role : 'assistant'
|
|
2898
|
+
});
|
|
2899
|
+
const langChainMessage = super._convertCompletionsMessageToBaseMessage(normalizedMessage, rawResponse);
|
|
2681
2900
|
console.log(langChainMessage.content);
|
|
2682
2901
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2683
2902
|
if (message.reasoning_content) {
|
|
@@ -2862,66 +3081,6 @@ Reflect.defineMetadata(COMMAND_METADATA$1, {
|
|
|
2862
3081
|
id: CreateModelClientCommand.type
|
|
2863
3082
|
}, CreateModelClientCommand);
|
|
2864
3083
|
|
|
2865
|
-
const KnowledgebaseRuntimeCapability = createRuntimeCapability('platform.knowledgebase', {
|
|
2866
|
-
description: 'List, search, and write chunks in platform knowledgebases.'
|
|
2867
|
-
});
|
|
2868
|
-
|
|
2869
|
-
const KnowledgebaseDocumentsRuntimeCapability = createRuntimeCapability('platform.knowledgebase.documents', {
|
|
2870
|
-
description: 'Upload, import, create, process, inspect, and delete persistent knowledgebase documents.'
|
|
2871
|
-
});
|
|
2872
|
-
|
|
2873
|
-
const ActorTokenRuntimeCapability = createRuntimeCapability('platform.actor-token', {
|
|
2874
|
-
description: 'Mint a short-lived host-issued actor bearer token for outbound API calls.'
|
|
2875
|
-
});
|
|
2876
|
-
|
|
2877
|
-
const ArtifactsRuntimeCapability = createRuntimeCapability('platform.artifacts', {
|
|
2878
|
-
description: 'Create, version, preview, download, share, archive, and delete platform-managed plugin and Agent artifacts.'
|
|
2879
|
-
});
|
|
2880
|
-
|
|
2881
|
-
/** Stable source identifier for portable workspace file references. */ const WORKSPACE_FILES_SOURCE = 'platform.workspace.files';
|
|
2882
|
-
const WorkspaceFilesRuntimeCapability = createRuntimeCapability('platform.workspace.files', {
|
|
2883
|
-
description: 'Upload, understand, resolve, read, and delete raw files in Xpert workspace volumes.'
|
|
2884
|
-
});
|
|
2885
|
-
|
|
2886
|
-
/** Stable machine-readable failures emitted by the Sandbox Jobs capability. */ const SANDBOX_JOB_ERROR_CODES = [
|
|
2887
|
-
'SANDBOX_ACTION_UNAVAILABLE',
|
|
2888
|
-
'SANDBOX_ACTION_INVALID',
|
|
2889
|
-
'SANDBOX_PROFILE_UNAVAILABLE',
|
|
2890
|
-
'SANDBOX_RUNTIME_UNAVAILABLE',
|
|
2891
|
-
'SANDBOX_VERSION_MISMATCH',
|
|
2892
|
-
'SANDBOX_CAPACITY_UNAVAILABLE',
|
|
2893
|
-
'SANDBOX_START_FAILED',
|
|
2894
|
-
'BROWSER_LAUNCH_FAILED',
|
|
2895
|
-
'EXPORT_TIMEOUT',
|
|
2896
|
-
'EXPORT_OOM',
|
|
2897
|
-
'EXPORT_MEDIA_FAILED',
|
|
2898
|
-
'EXPORT_INPUT_INVALID',
|
|
2899
|
-
'EXPORT_OUTPUT_INVALID',
|
|
2900
|
-
'SANDBOX_CANCELLED'
|
|
2901
|
-
];
|
|
2902
|
-
/** Line prefix used by trusted Actions to report structured, provider-neutral progress. */ const SANDBOX_JOB_PROGRESS_PREFIX = 'XPERT_SANDBOX_PROGRESS ';
|
|
2903
|
-
/** Error carrying retry policy and Job identity across plugin queue handlers. */ class SandboxJobRuntimeError extends Error {
|
|
2904
|
-
constructor(code, message, retryable, jobId){
|
|
2905
|
-
super(message);
|
|
2906
|
-
this.code = code;
|
|
2907
|
-
this.retryable = retryable;
|
|
2908
|
-
this.jobId = jobId;
|
|
2909
|
-
this.name = 'SandboxJobRuntimeError';
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
const SANDBOX_JOB_ERROR_CODE_SET = new Set(SANDBOX_JOB_ERROR_CODES);
|
|
2913
|
-
/** Narrows an unknown failure to the structured Sandbox Jobs runtime error contract. */ function isSandboxJobRuntimeError(error) {
|
|
2914
|
-
if (error instanceof SandboxJobRuntimeError) return true;
|
|
2915
|
-
if (typeof error !== 'object' || error === null) return false;
|
|
2916
|
-
// Dynamically loaded plugins may resolve another Plugin SDK module instance,
|
|
2917
|
-
// so class identity is not a reliable runtime boundary. Validate the stable shape.
|
|
2918
|
-
const candidate = error;
|
|
2919
|
-
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');
|
|
2920
|
-
}
|
|
2921
|
-
/** Runtime capability key used to resolve SandboxJobsApi from the platform registry. */ const SandboxJobsRuntimeCapability = createRuntimeCapability('platform.sandbox.jobs', {
|
|
2922
|
-
description: 'Run registered plugin actions in isolated, short-lived Sandbox Runtime jobs.'
|
|
2923
|
-
});
|
|
2924
|
-
|
|
2925
3084
|
const SKILL_SOURCE_PROVIDER = 'SKILL_SOURCE_PROVIDER';
|
|
2926
3085
|
const SkillSourceProviderStrategy = (provider)=>applyDecorators(SetMetadata(SKILL_SOURCE_PROVIDER, provider), SetMetadata(STRATEGY_META_KEY, SKILL_SOURCE_PROVIDER));
|
|
2927
3086
|
|
|
@@ -2970,6 +3129,32 @@ const FileRuntimeCapability = createRuntimeCapability('platform.file', {
|
|
|
2970
3129
|
description: 'Resolve platform file handles into previewable file URLs.'
|
|
2971
3130
|
});
|
|
2972
3131
|
|
|
3132
|
+
const XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN = 'XPERT_AGENT_MIDDLEWARE_RUNTIME';
|
|
3133
|
+
|
|
3134
|
+
const MODEL_OUTPUT_VALIDATION_ERROR_CODE = 'MODEL_OUTPUT_VALIDATION_ERROR';
|
|
3135
|
+
/**
|
|
3136
|
+
* Signals that the provider returned a model response which could not be
|
|
3137
|
+
* accepted, but can be regenerated safely because no tool was executed.
|
|
3138
|
+
*
|
|
3139
|
+
* Keep `repairContext` compact and free of raw tool arguments. Model
|
|
3140
|
+
* middleware may use it as retry-local feedback, so it must never contain
|
|
3141
|
+
* credentials, complete documents, or other unbounded model output.
|
|
3142
|
+
*/ class ModelOutputValidationError extends Error {
|
|
3143
|
+
constructor(message, repairContext){
|
|
3144
|
+
super(message);
|
|
3145
|
+
this.code = MODEL_OUTPUT_VALIDATION_ERROR_CODE;
|
|
3146
|
+
this.retryable = true;
|
|
3147
|
+
this.repairContext = repairContext;
|
|
3148
|
+
this.name = 'ModelOutputValidationError';
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
function isModelOutputValidationError(error) {
|
|
3152
|
+
var _candidate_repairContext;
|
|
3153
|
+
if (!error || typeof error !== 'object') return false;
|
|
3154
|
+
const candidate = error;
|
|
3155
|
+
return candidate.code === MODEL_OUTPUT_VALIDATION_ERROR_CODE && candidate.retryable === true && ((_candidate_repairContext = candidate.repairContext) == null ? void 0 : _candidate_repairContext.kind) === 'invalid_tool_calls' && Array.isArray(candidate.repairContext.issues);
|
|
3156
|
+
}
|
|
3157
|
+
|
|
2973
3158
|
const SEGMENT_PATTERN = /^[a-z][a-z0-9_-]*$/i;
|
|
2974
3159
|
const VERSION_PATTERN = /^v[1-9][0-9]*$/;
|
|
2975
3160
|
function assertSegment(input, name) {
|
|
@@ -4986,4 +5171,28 @@ CollaborationDocumentProviderRegistry = __decorate([
|
|
|
4986
5171
|
])
|
|
4987
5172
|
], CollaborationDocumentProviderRegistry);
|
|
4988
5173
|
|
|
4989
|
-
|
|
5174
|
+
const EVOLUTION_TARGET_PROVIDER = 'EVOLUTION_TARGET_PROVIDER';
|
|
5175
|
+
const EvolutionTargetProviderStrategy = (providerKey)=>applyDecorators(SetMetadata(EVOLUTION_TARGET_PROVIDER, providerKey), SetMetadata(STRATEGY_META_KEY, EVOLUTION_TARGET_PROVIDER));
|
|
5176
|
+
|
|
5177
|
+
let EvolutionTargetProviderRegistry = class EvolutionTargetProviderRegistry extends BaseStrategyRegistry {
|
|
5178
|
+
listDescriptors(organizationId) {
|
|
5179
|
+
return this.list(organizationId).map((provider)=>provider.descriptor);
|
|
5180
|
+
}
|
|
5181
|
+
constructor(discoveryService, reflector){
|
|
5182
|
+
super(EVOLUTION_TARGET_PROVIDER, discoveryService, reflector);
|
|
5183
|
+
}
|
|
5184
|
+
};
|
|
5185
|
+
EvolutionTargetProviderRegistry = __decorate([
|
|
5186
|
+
Injectable(),
|
|
5187
|
+
__metadata("design:paramtypes", [
|
|
5188
|
+
DiscoveryService,
|
|
5189
|
+
Reflector
|
|
5190
|
+
])
|
|
5191
|
+
], EvolutionTargetProviderRegistry);
|
|
5192
|
+
|
|
5193
|
+
const EVOLUTION_RUNTIME_SERVICE_TOKEN = 'XPERT_EVOLUTION_RUNTIME_SERVICE';
|
|
5194
|
+
const EvolutionRuntimeCapability = createRuntimeCapability('platform.agent-evolution', {
|
|
5195
|
+
description: 'Ingest learning signals and resolve immutable capability versions for domain runtimes.'
|
|
5196
|
+
});
|
|
5197
|
+
|
|
5198
|
+
export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_ERROR_STEER_TARGET_NOT_RUNNING, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, AdapterDataSourceStrategy, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AiModelNotFoundException, AssistantTaskRuntimeCapability, BOUND_IDENTITY_LOGIN_PERMISSION_SERVICE_TOKEN, BUILTIN_GLOBAL_SCOPE, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseSandbox, BaseStrategyRegistry, CHAT_CHANNEL, CHAT_CHANNEL_TEXT_LIMITS, COLLABORATION_DOCUMENT_PROVIDER, CONNECTION_COMMAND_ROUTER_TOKEN, CONNECTOR_STRATEGY, CancelConversationCommand, ChatChannel, ChatChannelRegistry, ChatOAICompatReasoningModel, CollaborationDocumentProvider, CollaborationDocumentProviderRegistry, CollaborationRuntimeCapability, CommonParameterRules, ConnectorRuntimeCapability, ConnectorStrategyKey, ConnectorStrategyRegistry, CreateModelClientCommand, CredentialsValidateFailedError, DATASOURCE_STRATEGY, DBCreateTableMode, DBProtocolEnum, DBSyntaxEnum, DBTableAction, DBTableDataAction, DEFAULT_EXECUTION_CONFIG, DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS, DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC, DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS, DEFAULT_SANDBOX_SHELL_TIMEOUT_MS, DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DataSourceStrategy, DataSourceStrategyRegistry, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, EVOLUTION_RUNTIME_SERVICE_TOKEN, EVOLUTION_TARGET_PROVIDER, EvolutionRuntimeCapability, EvolutionTargetProviderRegistry, EvolutionTargetProviderStrategy, 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, ImageGenerationModel, ImageUnderstandingRegistry, ImageUnderstandingStrategy, IntegrationStrategyKey, IntegrationStrategyRegistry, JUMP_TO_TARGETS, JsonSchemaValidator, KNOWLEDGE_STRATEGY, KnowledgeStrategyKey, KnowledgeStrategyRegistry, LLMUsage, LargeLanguageModel, MANAGED_CONNECTION_REGISTRY_TOKEN, MANAGED_QUEUE_HANDLER_REGISTRY_TOKEN, MANAGED_QUEUE_SERVICE_TOKEN, MODEL_OUTPUT_VALIDATION_ERROR_CODE, ModelOutputValidationError, ModelProvider, ORGANIZATION_METADATA_KEY, OpenAICompatibleReranker, PERMISSION_OPERATION_METADATA_KEY, PLUGIN_CONFIG_RESOLVER_TOKEN, PLUGIN_JOB_PROCESSOR_METADATA, 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, PluginJobProcessor, PluginWebhookAuth, PluginWebhookAuthGuard, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RequirePermissionOperation, RerankModel, RetrieverRegistry, RetrieverStrategy, SANDBOX_PROVIDER, SANDBOX_RUNTIME_PROVIDER, SANDBOX_SHELL_TIMEOUT_LIMITS_SEC, SANDBOX_WORKSPACE_MAPPER, 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, SYSTEM_GLOBAL_SCOPE, SandboxProviderRegistry, SandboxProviderStrategy, SandboxRuntimeProviderRegistry, SandboxRuntimeProviderStrategy, SandboxWorkspaceMapperRegistry, SandboxWorkspaceMapperStrategy, 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, VIDEO_GENERATION_PERMISSION_SERVICE_TOKEN, VIDEO_GENERATION_SERVICE_TOKEN, VIDEO_GENERATOR_FAMILIES, VIEW_EXTENSION_CACHE_SERVICE_TOKEN, VIEW_EXTENSION_PROVIDER, VectorStoreRegistry, VectorStoreStrategy, VideoGenerationModel, ViewExtensionProvider, ViewExtensionProviderRegistry, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WrapWorkflowNodeExecutionCommand, XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN, XpFileSystem, XpertServerPlugin, als, appendSandboxMessage, assertConnectorDefinition, buildSandboxTimeoutMessage, calcTokenUsage, calculateModelPrice, calculateModelUsageCharge, chunkText, countTokensSafe, createI18nInstance, createPluginLogger, createRuntimeCapability, defineAgentMessageType, defineChannelMessageType, derivePluginArtifactNamespace, downloadRemoteFile, formatSandboxTimeout, getDefaultTenantId, getErrorMessage, getModelContextSize, getPermissionOperationMetadata, getPositionList, getPositionMap, getRequestContext, getRequiredPermissionOperation, getTenantGlobalScopeKey, isDevelopmentSandboxRuntimeEnvironment, isModelOutputValidationError, isModelUsagePricingConfig, isRemoteFile, isSandboxBackend, isSandboxManagedServiceAdapter, isSandboxServiceProxyAdapter, isSandboxTerminalAdapter, isStrategyInstance, isStructuredMessageType, isTenantGlobalScopeKey, loadYamlFile, mergeCredentials, mergeParentChildChunks, normalizeContextSize, pluginArtifactTableName, processAsyncAIGCManagedJob, renderRemoteModuleIframeHtml, renderRemoteReactIframeHtml, renderRemoteVueIframeHtml, resolveModelUsagePricingSnapshot, resolveSandboxBackend, resolveSandboxExecutionOptions, resolveSandboxManagedServiceAdapter, resolveSandboxServiceProxyAdapter, resolveSandboxTerminalAdapter, resolveStrategyMetadataTarget, resolveTenantGlobalScopeKey, resolveTokenUsage, runWithRequestContext, secondsToMilliseconds, setDefaultTenantId, sumTokenUsage };
|