@xpert-ai/plugin-sdk 3.17.1 → 3.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import { pick } from 'lodash-es';
4
4
  import { _ as _extends } from './_extends.esm.js';
5
5
  import { DiscoveryService, Reflector } from '@nestjs/core';
6
6
  import { Subject, filter } from 'rxjs';
7
- import { LanguagesEnum, AiModelTypeEnum, ParameterType, PriceType, FetchFrom, ModelFeature, ModelPropertyKey } from '@xpert-ai/contracts';
7
+ import { LanguagesEnum, ParameterType, AiModelTypeEnum, PriceType, FetchFrom, ModelFeature, ModelPropertyKey } from '@xpert-ai/contracts';
8
8
  export { ASSISTANT_CHAT_SEND_MESSAGE_COMMAND, ASSISTANT_CONTEXT_SET_COMMAND } from '@xpert-ai/contracts';
9
9
  import { AsyncLocalStorage } from 'node:async_hooks';
10
10
  import { ExtractJwt } from 'passport-jwt';
@@ -16,7 +16,7 @@ import fs__default from 'fs';
16
16
  import http from 'http';
17
17
  import https from 'https';
18
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';
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 KnowledgeDocumentVisualAssetsRuntimeCapability, e as KnowledgebaseDocumentsRuntimeCapability, f as KnowledgebaseProvisioningRuntimeCapability, g as KnowledgebaseRuntimeCapability, M as ModelProviderBuiltinToolset, P as ProjectProvisioningRuntimeCapability, S as SANDBOX_JOB_ERROR_CODES, h as SANDBOX_JOB_PROGRESS_PREFIX, i as SandboxJobRuntimeError, j as SandboxJobsRuntimeCapability, W as WORKSPACE_FILES_SOURCE, k as WorkspaceFilesRuntimeCapability, X as XPERT_RUNTIME_CAPABILITIES_TOKEN, l as isSandboxJobRuntimeError } from './model-provider.esm.js';
20
20
  import fsPromises from 'fs/promises';
21
21
  import * as path from 'path';
22
22
  import path__default, { join } from 'path';
@@ -1651,145 +1651,6 @@ AIModelProviderRegistry = __decorate([
1651
1651
  ])
1652
1652
  ], AIModelProviderRegistry);
1653
1653
 
1654
- class AiModelNotFoundException extends NotFoundException {
1655
- }
1656
- class CredentialsValidateFailedError extends ForbiddenException {
1657
- }
1658
- class AIModelProviderNotFoundException extends NotFoundException {
1659
- }
1660
-
1661
- var ModelProvider_1;
1662
- let ModelProvider = ModelProvider_1 = class ModelProvider {
1663
- get name() {
1664
- return this.getProviderSchema().provider;
1665
- }
1666
- async validateCredentials(credentials) {
1667
- await this.validateProviderCredentials(credentials);
1668
- }
1669
- /**
1670
- * Get provider lib root path.
1671
- *
1672
- * @returns Root of library
1673
- */ getProviderServerPath() {
1674
- return this.dir;
1675
- }
1676
- getProviderSchema() {
1677
- if (this._meta) {
1678
- return this._meta;
1679
- }
1680
- const yamlPath = join(this.getProviderServerPath(), `${this._name}.yaml`);
1681
- const yamlData = loadYamlFile(yamlPath, this.logger);
1682
- try {
1683
- this._meta = yamlData;
1684
- } catch (e) {
1685
- throw new Error(`Invalid provider schema for ${this.name}: ${e.message}`);
1686
- }
1687
- return this._meta;
1688
- }
1689
- async getModels(modelType) {
1690
- const providerSchema = this.getProviderSchema();
1691
- const supported = providerSchema.supported_model_types.includes(modelType) || modelType === AiModelTypeEnum.IMAGE && providerSchema.supported_model_types.includes(AiModelTypeEnum.TEXT2IMG);
1692
- if (!supported) {
1693
- return [];
1694
- }
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
- }
1700
- return modelInstance.predefinedModels();
1701
- }
1702
- registerAIModelInstance(modelType, modelInstance) {
1703
- this.modelManagers.set(modelType, modelInstance);
1704
- }
1705
- getModelManager(modelType) {
1706
- const modelInstance = this.modelManagers.get(modelType);
1707
- if (!modelInstance) {
1708
- throw new AiModelNotFoundException(`Missing AIModel instance for model type ${modelType}`);
1709
- }
1710
- return modelInstance;
1711
- }
1712
- /**
1713
- * Get provider models.
1714
- * @param modelType - model type
1715
- * @param onlyActive - only active models
1716
- * @return provider models
1717
- */ getProviderModels(modelType, onlyActive = false) {
1718
- let modelTypes = [];
1719
- if (modelType) {
1720
- modelTypes.push(modelType);
1721
- } else {
1722
- modelTypes = this.getProviderSchema().supported_model_types;
1723
- }
1724
- const providerModels = this.getSystemProviderModels(modelTypes);
1725
- // Resort providerModels
1726
- return providerModels.sort((a, b)=>a.model_type.localeCompare(b.model_type));
1727
- }
1728
- getSystemProviderModels(modelTypes) {
1729
- const models = [];
1730
- modelTypes == null ? void 0 : modelTypes.forEach((modelType)=>{
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);
1733
- if (modelManager) {
1734
- models.push(...modelManager.predefinedModels());
1735
- }
1736
- });
1737
- return models;
1738
- }
1739
- getChatModel(copilotModel, options) {
1740
- var _this_getModelManager;
1741
- return (_this_getModelManager = this.getModelManager(AiModelTypeEnum.LLM)) == null ? void 0 : _this_getModelManager.getChatModel(copilotModel, options);
1742
- }
1743
- async getModelInstance(type, copilotModel, options) {
1744
- switch(type){
1745
- case AiModelTypeEnum.LLM:
1746
- var _this_getModelManager;
1747
- return (_this_getModelManager = this.getModelManager(type)) == null ? void 0 : _this_getModelManager.getChatModel(copilotModel, options);
1748
- case AiModelTypeEnum.TEXT_EMBEDDING:
1749
- var _this_getModelManager1;
1750
- if (!copilotModel.options) {
1751
- var _copilotModel_copilot_copilotModel, _predefinedModels_find;
1752
- const predefinedModels = await this.getModels(AiModelTypeEnum.TEXT_EMBEDDING);
1753
- const modelName = copilotModel.model || ((_copilotModel_copilot_copilotModel = copilotModel.copilot.copilotModel) == null ? void 0 : _copilotModel_copilot_copilotModel.model);
1754
- copilotModel.options = (_predefinedModels_find = predefinedModels.find((_)=>_.model === modelName)) == null ? void 0 : _predefinedModels_find.model_properties;
1755
- }
1756
- return (_this_getModelManager1 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager1.getEmbeddingInstance(copilotModel, options);
1757
- case AiModelTypeEnum.TTS:
1758
- var _this_getModelManager2;
1759
- return (_this_getModelManager2 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager2.getChatModel(copilotModel, options);
1760
- case AiModelTypeEnum.SPEECH2TEXT:
1761
- var _this_getModelManager3;
1762
- return (_this_getModelManager3 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager3.getChatModel(copilotModel, options);
1763
- case AiModelTypeEnum.RERANK:
1764
- var _this_getModelManager4;
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);
1774
- }
1775
- return null;
1776
- }
1777
- constructor(){
1778
- this.logger = new Logger(ModelProvider_1.name);
1779
- // protected providerSchema: IAiProviderEntity | null = null
1780
- this.modelManagers = new Map();
1781
- const provider = Reflect.getMetadata(AI_MODEL_PROVIDER, this.constructor);
1782
- this._name = provider;
1783
- // Automatically retrieve provider DIR information from decorator metadata
1784
- const dir = Reflect.getMetadata(`${AI_MODEL_PROVIDER}_DIR`, this.constructor);
1785
- this.dir = dir;
1786
- }
1787
- };
1788
- ModelProvider = ModelProvider_1 = __decorate([
1789
- Injectable(),
1790
- __metadata("design:paramtypes", [])
1791
- ], ModelProvider);
1792
-
1793
1654
  function valueOf(enumObj, value) {
1794
1655
  const enumValues = Object.values(enumObj);
1795
1656
  if (enumValues.includes(value)) {
@@ -1935,6 +1796,145 @@ const PARAMETER_RULE_TEMPLATE = {
1935
1796
  }
1936
1797
  };
1937
1798
 
1799
+ class AiModelNotFoundException extends NotFoundException {
1800
+ }
1801
+ class CredentialsValidateFailedError extends ForbiddenException {
1802
+ }
1803
+ class AIModelProviderNotFoundException extends NotFoundException {
1804
+ }
1805
+
1806
+ var ModelProvider_1;
1807
+ let ModelProvider = ModelProvider_1 = class ModelProvider {
1808
+ get name() {
1809
+ return this.getProviderSchema().provider;
1810
+ }
1811
+ async validateCredentials(credentials) {
1812
+ await this.validateProviderCredentials(credentials);
1813
+ }
1814
+ /**
1815
+ * Get provider lib root path.
1816
+ *
1817
+ * @returns Root of library
1818
+ */ getProviderServerPath() {
1819
+ return this.dir;
1820
+ }
1821
+ getProviderSchema() {
1822
+ if (this._meta) {
1823
+ return this._meta;
1824
+ }
1825
+ const yamlPath = join(this.getProviderServerPath(), `${this._name}.yaml`);
1826
+ const yamlData = loadYamlFile(yamlPath, this.logger);
1827
+ try {
1828
+ this._meta = yamlData;
1829
+ } catch (e) {
1830
+ throw new Error(`Invalid provider schema for ${this.name}: ${e.message}`);
1831
+ }
1832
+ return this._meta;
1833
+ }
1834
+ async getModels(modelType) {
1835
+ const providerSchema = this.getProviderSchema();
1836
+ const supported = providerSchema.supported_model_types.includes(modelType) || modelType === AiModelTypeEnum.IMAGE && providerSchema.supported_model_types.includes(AiModelTypeEnum.TEXT2IMG);
1837
+ if (!supported) {
1838
+ return [];
1839
+ }
1840
+ var _this_modelManagers_get;
1841
+ 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);
1842
+ if (!modelInstance) {
1843
+ throw new AiModelNotFoundException(`Missing AIModel instance for model type ${modelType}`);
1844
+ }
1845
+ return modelInstance.predefinedModels();
1846
+ }
1847
+ registerAIModelInstance(modelType, modelInstance) {
1848
+ this.modelManagers.set(modelType, modelInstance);
1849
+ }
1850
+ getModelManager(modelType) {
1851
+ const modelInstance = this.modelManagers.get(modelType);
1852
+ if (!modelInstance) {
1853
+ throw new AiModelNotFoundException(`Missing AIModel instance for model type ${modelType}`);
1854
+ }
1855
+ return modelInstance;
1856
+ }
1857
+ /**
1858
+ * Get provider models.
1859
+ * @param modelType - model type
1860
+ * @param onlyActive - only active models
1861
+ * @return provider models
1862
+ */ getProviderModels(modelType, onlyActive = false) {
1863
+ let modelTypes = [];
1864
+ if (modelType) {
1865
+ modelTypes.push(modelType);
1866
+ } else {
1867
+ modelTypes = this.getProviderSchema().supported_model_types;
1868
+ }
1869
+ const providerModels = this.getSystemProviderModels(modelTypes);
1870
+ // Resort providerModels
1871
+ return providerModels.sort((a, b)=>a.model_type.localeCompare(b.model_type));
1872
+ }
1873
+ getSystemProviderModels(modelTypes) {
1874
+ const models = [];
1875
+ modelTypes == null ? void 0 : modelTypes.forEach((modelType)=>{
1876
+ var _this_modelManagers_get;
1877
+ 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);
1878
+ if (modelManager) {
1879
+ models.push(...modelManager.predefinedModels());
1880
+ }
1881
+ });
1882
+ return models;
1883
+ }
1884
+ getChatModel(copilotModel, options) {
1885
+ var _this_getModelManager;
1886
+ return (_this_getModelManager = this.getModelManager(AiModelTypeEnum.LLM)) == null ? void 0 : _this_getModelManager.getChatModel(copilotModel, options);
1887
+ }
1888
+ async getModelInstance(type, copilotModel, options) {
1889
+ switch(type){
1890
+ case AiModelTypeEnum.LLM:
1891
+ var _this_getModelManager;
1892
+ return (_this_getModelManager = this.getModelManager(type)) == null ? void 0 : _this_getModelManager.getChatModel(copilotModel, options);
1893
+ case AiModelTypeEnum.TEXT_EMBEDDING:
1894
+ var _this_getModelManager1;
1895
+ if (!copilotModel.options) {
1896
+ var _copilotModel_copilot_copilotModel, _predefinedModels_find;
1897
+ const predefinedModels = await this.getModels(AiModelTypeEnum.TEXT_EMBEDDING);
1898
+ const modelName = copilotModel.model || ((_copilotModel_copilot_copilotModel = copilotModel.copilot.copilotModel) == null ? void 0 : _copilotModel_copilot_copilotModel.model);
1899
+ copilotModel.options = (_predefinedModels_find = predefinedModels.find((_)=>_.model === modelName)) == null ? void 0 : _predefinedModels_find.model_properties;
1900
+ }
1901
+ return (_this_getModelManager1 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager1.getEmbeddingInstance(copilotModel, options);
1902
+ case AiModelTypeEnum.TTS:
1903
+ var _this_getModelManager2;
1904
+ return (_this_getModelManager2 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager2.getChatModel(copilotModel, options);
1905
+ case AiModelTypeEnum.SPEECH2TEXT:
1906
+ var _this_getModelManager3;
1907
+ return (_this_getModelManager3 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager3.getChatModel(copilotModel, options);
1908
+ case AiModelTypeEnum.RERANK:
1909
+ var _this_getModelManager4;
1910
+ return (_this_getModelManager4 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager4.getReranker(copilotModel, options);
1911
+ case AiModelTypeEnum.IMAGE:
1912
+ var _this;
1913
+ var _this_modelManagers_get;
1914
+ 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);
1915
+ case AiModelTypeEnum.TEXT2IMG:
1916
+ case AiModelTypeEnum.VIDEO:
1917
+ var _this_getModelManager5;
1918
+ return (_this_getModelManager5 = this.getModelManager(type)) == null ? void 0 : _this_getModelManager5.getAIGCModel(copilotModel, options);
1919
+ }
1920
+ return null;
1921
+ }
1922
+ constructor(){
1923
+ this.logger = new Logger(ModelProvider_1.name);
1924
+ // protected providerSchema: IAiProviderEntity | null = null
1925
+ this.modelManagers = new Map();
1926
+ const provider = Reflect.getMetadata(AI_MODEL_PROVIDER, this.constructor);
1927
+ this._name = provider;
1928
+ // Automatically retrieve provider DIR information from decorator metadata
1929
+ const dir = Reflect.getMetadata(`${AI_MODEL_PROVIDER}_DIR`, this.constructor);
1930
+ this.dir = dir;
1931
+ }
1932
+ };
1933
+ ModelProvider = ModelProvider_1 = __decorate([
1934
+ Injectable(),
1935
+ __metadata("design:paramtypes", [])
1936
+ ], ModelProvider);
1937
+
1938
1938
  const CommonParameterRules = [
1939
1939
  {
1940
1940
  name: 'temperature',
@@ -1996,33 +1996,143 @@ function calculateModelPrice(pricing, priceType, tokens, inputTokens = tokens) {
1996
1996
  currency: pricing.currency
1997
1997
  };
1998
1998
  }
1999
+ function calculateLLMUsagePrice(pricing, usage, context = {}) {
2000
+ var _pricing_rules;
2001
+ validateLLMPriceRules((_pricing_rules = pricing.rules) != null ? _pricing_rules : []);
2002
+ const pricingContext = _extends({}, context, {
2003
+ pricingTime: resolvePricingTime(context.pricingTime)
2004
+ });
2005
+ const promptTokens = tokenCount(usage.promptTokens, 'promptTokens');
2006
+ const completionTokens = tokenCount(usage.completionTokens, 'completionTokens');
2007
+ var _usage_cacheReadInputTokens;
2008
+ const cacheReadInputTokens = tokenCount((_usage_cacheReadInputTokens = usage.cacheReadInputTokens) != null ? _usage_cacheReadInputTokens : 0, 'cacheReadInputTokens');
2009
+ var _usage_cacheWriteInputTokens;
2010
+ const cacheWriteInputTokens = tokenCount((_usage_cacheWriteInputTokens = usage.cacheWriteInputTokens) != null ? _usage_cacheWriteInputTokens : 0, 'cacheWriteInputTokens');
2011
+ const cacheTokens = cacheReadInputTokens + cacheWriteInputTokens;
2012
+ const inputTokens = context.inputTokensIncludeCache === false ? promptTokens + cacheTokens : promptTokens;
2013
+ let standardInputTokens = context.inputTokensIncludeCache === false ? promptTokens : promptTokens - cacheTokens;
2014
+ if (standardInputTokens < 0) {
2015
+ throw new Error('Cache read and write tokens cannot exceed prompt tokens when input includes cache tokens');
2016
+ }
2017
+ const selectionContext = {
2018
+ inputTokens,
2019
+ outputTokens: completionTokens,
2020
+ context: pricingContext
2021
+ };
2022
+ const breakdown = [];
2023
+ const cacheReadRule = selectLLMPriceRule(pricing.rules, 'cache_read_input', selectionContext);
2024
+ if (cacheReadInputTokens > 0) {
2025
+ if (cacheReadRule) {
2026
+ breakdown.push(priceRuleComponent(cacheReadRule, cacheReadInputTokens, pricing.currency));
2027
+ } else if (hasLLMPriceRule(pricing.rules, 'cache_read_input')) {
2028
+ breakdown.push(unpricedComponent('cache_read_input', cacheReadInputTokens));
2029
+ } else {
2030
+ standardInputTokens += cacheReadInputTokens;
2031
+ }
2032
+ }
2033
+ for (const cacheWrite of resolveCacheWriteInputTokens(cacheWriteInputTokens, context)){
2034
+ const cacheWriteSelection = _extends({}, selectionContext, {
2035
+ context: _extends({}, pricingContext, {
2036
+ cacheWriteTtl: cacheWrite.cacheTtl
2037
+ })
2038
+ });
2039
+ const cacheWriteRule = selectLLMPriceRule(pricing.rules, 'cache_write_input', cacheWriteSelection);
2040
+ if (cacheWriteRule) {
2041
+ breakdown.push(priceRuleComponent(cacheWriteRule, cacheWrite.quantity, pricing.currency, {
2042
+ cacheTtl: cacheWrite.cacheTtl
2043
+ }));
2044
+ } else if (hasLLMPriceRule(pricing.rules, 'cache_write_input')) {
2045
+ breakdown.push(unpricedComponent('cache_write_input', cacheWrite.quantity, {
2046
+ cacheTtl: cacheWrite.cacheTtl
2047
+ }));
2048
+ } else {
2049
+ standardInputTokens += cacheWrite.quantity;
2050
+ }
2051
+ }
2052
+ if (standardInputTokens > 0) {
2053
+ const inputRule = selectLLMPriceRule(pricing.rules, 'input', selectionContext);
2054
+ breakdown.push(inputRule ? priceRuleComponent(inputRule, standardInputTokens, pricing.currency) : hasLLMPriceRule(pricing.rules, 'input') ? unpricedComponent('input', standardInputTokens) : legacyPriceComponent(pricing, PriceType.INPUT, standardInputTokens, inputTokens));
2055
+ }
2056
+ if (completionTokens > 0) {
2057
+ const outputRule = selectLLMPriceRule(pricing.rules, 'output', selectionContext);
2058
+ breakdown.push(outputRule ? priceRuleComponent(outputRule, completionTokens, pricing.currency) : hasLLMPriceRule(pricing.rules, 'output') ? unpricedComponent('output', completionTokens) : legacyPriceComponent(pricing, PriceType.OUTPUT, completionTokens, inputTokens));
2059
+ }
2060
+ const addOns = new Map();
2061
+ var _context_addOns;
2062
+ for (const addOn of (_context_addOns = context.addOns) != null ? _context_addOns : []){
2063
+ const quantity = nonNegativeQuantity(addOn.quantity, `add-on '${addOn.type}'`);
2064
+ if (quantity === 0) continue;
2065
+ var _addOns_get;
2066
+ addOns.set(addOn.type, ((_addOns_get = addOns.get(addOn.type)) != null ? _addOns_get : 0) + quantity);
2067
+ }
2068
+ for (const [addOn, quantity] of addOns){
2069
+ const rule = selectLLMPriceRule(pricing.rules, 'request', selectionContext, addOn);
2070
+ breakdown.push(rule ? priceRuleComponent(rule, quantity, pricing.currency, {
2071
+ addOn
2072
+ }) : unpricedComponent('request', quantity, {
2073
+ addOn
2074
+ }));
2075
+ }
2076
+ var _context_unpricedAddOns;
2077
+ for (const addOn of (_context_unpricedAddOns = context.unpricedAddOns) != null ? _context_unpricedAddOns : []){
2078
+ const quantity = nonNegativeQuantity(addOn.quantity, `unpriced add-on '${addOn.type}'`);
2079
+ if (quantity === 0) continue;
2080
+ breakdown.push(unpricedComponent('request', quantity, {
2081
+ addOn: addOn.type,
2082
+ addOnAuthority: addOn.authority
2083
+ }));
2084
+ }
2085
+ if (context.cacheStorageTokenHours !== undefined) {
2086
+ const quantity = nonNegativeQuantity(context.cacheStorageTokenHours, 'cacheStorageTokenHours');
2087
+ if (quantity > 0) {
2088
+ const rule = selectLLMPriceRule(pricing.rules, 'cache_storage', selectionContext);
2089
+ breakdown.push(rule ? priceRuleComponent(rule, quantity, pricing.currency) : unpricedComponent('cache_storage', quantity));
2090
+ }
2091
+ }
2092
+ return summarizeLLMPrice(pricing.currency, breakdown);
2093
+ }
1999
2094
  function resolveModelUsagePricingSnapshot(pricing, context) {
2000
2095
  var _normalizeDate;
2001
2096
  var _normalizeDate_toISOString;
2002
2097
  const capturedAt = (_normalizeDate_toISOString = (_normalizeDate = normalizeDate(context.startedAt)) == null ? void 0 : _normalizeDate.toISOString()) != null ? _normalizeDate_toISOString : new Date().toISOString();
2003
2098
  if (!isModelUsagePricingConfig(pricing)) {
2004
- return {
2005
- capturedAt,
2099
+ return _extends({
2100
+ capturedAt
2101
+ }, context.pricingDimensions ? {
2102
+ pricingDimensions: context.pricingDimensions
2103
+ } : {}, {
2006
2104
  rules: []
2007
- };
2105
+ });
2008
2106
  }
2009
2107
  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){
2108
+ const matchingRules = pricing.rules.filter((rule)=>matchesUsagePriceRule(rule, context, at));
2109
+ const rules = [];
2110
+ for (const rule of matchingRules){
2013
2111
  validateUsagePriceRule(rule);
2014
- if (units.has(rule.unit)) {
2112
+ const selector = usagePriceRuleSelector(rule);
2113
+ const existingIndex = rules.findIndex((candidate)=>usagePriceRuleSelector(candidate) === selector);
2114
+ if (existingIndex < 0) {
2115
+ rules.push(rule);
2116
+ continue;
2117
+ }
2118
+ const existing = rules[existingIndex];
2119
+ const existingHasWindow = Boolean(existing.daily_time_window);
2120
+ const currentHasWindow = Boolean(rule.daily_time_window);
2121
+ if (existingHasWindow === currentHasWindow) {
2015
2122
  throw new Error(`Ambiguous usage pricing rules for unit '${rule.unit}'`);
2016
2123
  }
2017
- units.add(rule.unit);
2124
+ if (currentHasWindow) rules[existingIndex] = rule;
2018
2125
  }
2019
- return {
2020
- capturedAt,
2126
+ return _extends({
2127
+ capturedAt
2128
+ }, context.pricingDimensions ? {
2129
+ pricingDimensions: context.pricingDimensions
2130
+ } : {}, {
2021
2131
  rules
2022
- };
2132
+ });
2023
2133
  }
2024
2134
  function calculateModelUsageCharge(snapshot, metric) {
2025
- const rule = snapshot == null ? void 0 : snapshot.rules.find((candidate)=>candidate.unit === metric.unit);
2135
+ const rule = selectUsagePriceRule(snapshot, metric);
2026
2136
  const fallbackQuantity = metricQuantity(metric);
2027
2137
  if (!rule) {
2028
2138
  return {
@@ -2065,8 +2175,40 @@ function matchesUsagePriceRule(rule, context, at) {
2065
2175
  const effectiveTo = normalizeDate(rule.effective_to);
2066
2176
  if (!effectiveFrom || effectiveFrom > at || effectiveTo && effectiveTo <= at) return false;
2067
2177
  if (((_rule_operations = rule.operations) == null ? void 0 : _rule_operations.length) && !rule.operations.includes(context.operation)) return false;
2178
+ if (rule.daily_time_window) {
2179
+ validateRecurringDailyWindow(rule.daily_time_window);
2180
+ if (!isInRecurringDailyWindow(rule.daily_time_window, at)) return false;
2181
+ }
2068
2182
  var _context_pricingDimensions;
2069
2183
  const dimensions = (_context_pricingDimensions = context.pricingDimensions) != null ? _context_pricingDimensions : {};
2184
+ var _rule_dimensions;
2185
+ return Object.entries((_rule_dimensions = rule.dimensions) != null ? _rule_dimensions : {}).every(([key, value])=>{
2186
+ if (key === 'resolution') return dimensions.resolution === undefined || dimensions.resolution === value;
2187
+ if (key === 'audio') return dimensions.audio === undefined || dimensions.audio === value;
2188
+ if (key === 'videoInput') return dimensions.videoInput === undefined || dimensions.videoInput === value;
2189
+ if (key === 'mode') return dimensions.mode === undefined || dimensions.mode === value;
2190
+ return false;
2191
+ });
2192
+ }
2193
+ function selectUsagePriceRule(snapshot, metric) {
2194
+ var _snapshot_pricingDimensions, _metric_pricingDimensions;
2195
+ const dimensions = _extends({}, (_snapshot_pricingDimensions = snapshot == null ? void 0 : snapshot.pricingDimensions) != null ? _snapshot_pricingDimensions : {}, (_metric_pricingDimensions = metric.pricingDimensions) != null ? _metric_pricingDimensions : {});
2196
+ var _snapshot_rules;
2197
+ const matches = ((_snapshot_rules = snapshot == null ? void 0 : snapshot.rules) != null ? _snapshot_rules : []).filter((rule)=>{
2198
+ if (rule.unit !== metric.unit) return false;
2199
+ if (rule.component && rule.component !== metric.component) return false;
2200
+ return matchesUsagePriceDimensions(rule, dimensions);
2201
+ });
2202
+ if (!matches.length) return undefined;
2203
+ const specificity = Math.max(...matches.map(usagePriceRuleSpecificity));
2204
+ const mostSpecific = matches.filter((rule)=>usagePriceRuleSpecificity(rule) === specificity);
2205
+ if (mostSpecific.length > 1) {
2206
+ var _metric_key;
2207
+ throw new Error(`Ambiguous usage pricing rules for metric '${(_metric_key = metric.key) != null ? _metric_key : metric.unit}'`);
2208
+ }
2209
+ return mostSpecific[0];
2210
+ }
2211
+ function matchesUsagePriceDimensions(rule, dimensions) {
2070
2212
  var _rule_dimensions;
2071
2213
  return Object.entries((_rule_dimensions = rule.dimensions) != null ? _rule_dimensions : {}).every(([key, value])=>{
2072
2214
  if (key === 'resolution') return dimensions.resolution === value;
@@ -2076,15 +2218,36 @@ function matchesUsagePriceRule(rule, context, at) {
2076
2218
  return false;
2077
2219
  });
2078
2220
  }
2221
+ function usagePriceRuleSpecificity(rule) {
2222
+ var _rule_dimensions;
2223
+ return (rule.component ? 1 : 0) + Object.keys((_rule_dimensions = rule.dimensions) != null ? _rule_dimensions : {}).length;
2224
+ }
2225
+ function usagePriceRuleSelector(rule) {
2226
+ var _rule_token_type, _rule_component, _rule_dimensions;
2227
+ return JSON.stringify([
2228
+ rule.unit,
2229
+ (_rule_token_type = rule.token_type) != null ? _rule_token_type : null,
2230
+ (_rule_component = rule.component) != null ? _rule_component : null,
2231
+ Object.entries((_rule_dimensions = rule.dimensions) != null ? _rule_dimensions : {}).sort(([left], [right])=>left.localeCompare(right))
2232
+ ]);
2233
+ }
2079
2234
  function validateUsagePriceRule(rule) {
2080
2235
  var _rule_id, _rule_version;
2081
2236
  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');
2237
+ if (rule.component && ![
2238
+ 'input',
2239
+ 'output',
2240
+ 'request'
2241
+ ].includes(rule.component)) {
2242
+ throw new Error(`Usage pricing rule '${rule.id}' has an invalid component`);
2243
+ }
2082
2244
  if (!Number.isFinite(Number(rule.unit_size)) || Number(rule.unit_size) <= 0) {
2083
2245
  throw new Error(`Usage pricing rule '${rule.id}' requires a positive unit_size`);
2084
2246
  }
2085
2247
  if (rule.unit !== 'token' && rule.token_type) {
2086
2248
  throw new Error(`Usage pricing rule '${rule.id}' can only use token_type with token pricing`);
2087
2249
  }
2250
+ if (rule.daily_time_window) validateRecurringDailyWindow(rule.daily_time_window);
2088
2251
  if (rule.charge_type === 'paid') {
2089
2252
  var _rule_currency;
2090
2253
  if (!Number.isFinite(Number(rule.unit_price)) || Number(rule.unit_price) <= 0 || !((_rule_currency = rule.currency) == null ? void 0 : _rule_currency.trim())) {
@@ -2115,6 +2278,234 @@ function normalizeDate(value) {
2115
2278
  function roundCharge(value) {
2116
2279
  return Number(value.toFixed(10));
2117
2280
  }
2281
+ function hasLLMPriceRule(rules, component) {
2282
+ var _rules_some;
2283
+ return (_rules_some = rules == null ? void 0 : rules.some((rule)=>rule.component === component)) != null ? _rules_some : false;
2284
+ }
2285
+ function selectLLMPriceRule(rules, component, selection, addOn) {
2286
+ const matches = (rules != null ? rules : []).filter((rule)=>{
2287
+ if (rule.component !== component) return false;
2288
+ if (component === 'request' && rule.add_on !== addOn) return false;
2289
+ if (rule.cache_ttl && rule.cache_ttl !== selection.context.cacheWriteTtl) return false;
2290
+ if (rule.mode && rule.mode !== selection.context.mode) return false;
2291
+ if (rule.region && rule.region !== selection.context.region) return false;
2292
+ if (rule.service_tier && rule.service_tier !== selection.context.serviceTier) return false;
2293
+ if (rule.daily_time_window && !isInRecurringDailyWindow(rule.daily_time_window, selection.context.pricingTime)) {
2294
+ return false;
2295
+ }
2296
+ if (rule.min_input_tokens !== undefined && selection.inputTokens < Number(rule.min_input_tokens)) return false;
2297
+ if (rule.max_input_tokens !== undefined && selection.inputTokens > Number(rule.max_input_tokens)) return false;
2298
+ if (rule.min_output_tokens !== undefined && selection.outputTokens < Number(rule.min_output_tokens)) return false;
2299
+ if (rule.max_output_tokens !== undefined && selection.outputTokens > Number(rule.max_output_tokens)) return false;
2300
+ return true;
2301
+ });
2302
+ if (!matches.length) return undefined;
2303
+ const specificity = Math.max(...matches.map(ruleSpecificity));
2304
+ const mostSpecific = matches.filter((rule)=>ruleSpecificity(rule) === specificity);
2305
+ if (mostSpecific.length > 1) {
2306
+ throw new Error(`Ambiguous LLM pricing rules for component '${component}'`);
2307
+ }
2308
+ return mostSpecific[0];
2309
+ }
2310
+ function ruleSpecificity(rule) {
2311
+ return [
2312
+ rule.min_input_tokens,
2313
+ rule.max_input_tokens,
2314
+ rule.min_output_tokens,
2315
+ rule.max_output_tokens,
2316
+ rule.mode,
2317
+ rule.region,
2318
+ rule.service_tier,
2319
+ rule.add_on,
2320
+ rule.cache_ttl,
2321
+ rule.daily_time_window
2322
+ ].filter((value)=>value !== undefined).length;
2323
+ }
2324
+ function validateLLMPriceRules(rules) {
2325
+ for (const rule of rules){
2326
+ if (!Number.isFinite(Number(rule.unit_price)) || Number(rule.unit_price) < 0) {
2327
+ throw new Error(`LLM pricing rule '${rule.component}' requires a non-negative unit_price`);
2328
+ }
2329
+ if (!Number.isFinite(Number(rule.unit_size)) || Number(rule.unit_size) <= 0) {
2330
+ throw new Error(`LLM pricing rule '${rule.component}' requires a positive unit_size`);
2331
+ }
2332
+ if (rule.currency !== undefined && !rule.currency.trim()) {
2333
+ throw new Error(`LLM pricing rule '${rule.component}' requires a non-empty currency when provided`);
2334
+ }
2335
+ validateTokenRange(rule, 'input', rule.min_input_tokens, rule.max_input_tokens);
2336
+ validateTokenRange(rule, 'output', rule.min_output_tokens, rule.max_output_tokens);
2337
+ if (rule.component === 'request' && !rule.add_on) {
2338
+ throw new Error('LLM request pricing rules require add_on');
2339
+ }
2340
+ if (rule.component !== 'request' && rule.add_on) {
2341
+ throw new Error(`LLM pricing rule '${rule.component}' cannot declare add_on`);
2342
+ }
2343
+ if (rule.component !== 'cache_write_input' && rule.cache_ttl) {
2344
+ throw new Error(`LLM pricing rule '${rule.component}' cannot declare cache_ttl`);
2345
+ }
2346
+ if (rule.daily_time_window) validateRecurringDailyWindow(rule.daily_time_window);
2347
+ }
2348
+ }
2349
+ function validateTokenRange(rule, name, min, max) {
2350
+ const normalizedMin = min === undefined ? undefined : Number(min);
2351
+ const normalizedMax = max === undefined ? undefined : Number(max);
2352
+ if (normalizedMin !== undefined) tokenCount(normalizedMin, `min_${name}_tokens`);
2353
+ if (normalizedMax !== undefined) tokenCount(normalizedMax, `max_${name}_tokens`);
2354
+ if (normalizedMin !== undefined && normalizedMax !== undefined && normalizedMin > normalizedMax) {
2355
+ throw new Error(`LLM pricing rule '${rule.component}' has an invalid ${name} token range`);
2356
+ }
2357
+ }
2358
+ function validateRecurringDailyWindow(window) {
2359
+ validateTimeZone(window.time_zone);
2360
+ const start = parseLocalTime(window.start_time, 'start_time');
2361
+ const end = parseLocalTime(window.end_time, 'end_time');
2362
+ if (start === end) {
2363
+ throw new Error('Recurring daily pricing window start_time and end_time must differ');
2364
+ }
2365
+ }
2366
+ function validateTimeZone(timeZone) {
2367
+ try {
2368
+ new Intl.DateTimeFormat('en-US', {
2369
+ timeZone
2370
+ }).format();
2371
+ } catch (e) {
2372
+ throw new Error(`Invalid IANA time zone '${timeZone}'`);
2373
+ }
2374
+ }
2375
+ function parseLocalTime(value, name) {
2376
+ const match = /^(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(value);
2377
+ if (!match) {
2378
+ throw new Error(`Recurring daily pricing window ${name} must use HH:mm or HH:mm:ss`);
2379
+ }
2380
+ const hour = Number(match[1]);
2381
+ const minute = Number(match[2]);
2382
+ var _match_;
2383
+ const second = Number((_match_ = match[3]) != null ? _match_ : 0);
2384
+ if (hour > 23 || minute > 59 || second > 59) {
2385
+ throw new Error(`Recurring daily pricing window ${name} must be a valid wall-clock time`);
2386
+ }
2387
+ return hour * 3600 + minute * 60 + second;
2388
+ }
2389
+ function isInRecurringDailyWindow(window, pricingTime) {
2390
+ const instant = resolvePricingTime(pricingTime);
2391
+ const formatter = new Intl.DateTimeFormat('en-GB', {
2392
+ timeZone: window.time_zone,
2393
+ hourCycle: 'h23',
2394
+ hour: '2-digit',
2395
+ minute: '2-digit',
2396
+ second: '2-digit'
2397
+ });
2398
+ const values = Object.fromEntries(formatter.formatToParts(instant).filter((part)=>part.type === 'hour' || part.type === 'minute' || part.type === 'second').map((part)=>[
2399
+ part.type,
2400
+ Number(part.value)
2401
+ ]));
2402
+ const localTime = values['hour'] * 3600 + values['minute'] * 60 + values['second'];
2403
+ const start = parseLocalTime(window.start_time, 'start_time');
2404
+ const end = parseLocalTime(window.end_time, 'end_time');
2405
+ return start < end ? localTime >= start && localTime < end : localTime >= start || localTime < end;
2406
+ }
2407
+ function resolvePricingTime(value) {
2408
+ const instant = value instanceof Date ? new Date(value.getTime()) : value === undefined ? new Date() : new Date(value);
2409
+ if (!Number.isFinite(instant.getTime())) {
2410
+ throw new Error('pricingTime must be a valid date');
2411
+ }
2412
+ return instant;
2413
+ }
2414
+ function priceRuleComponent(rule, quantity, fallbackCurrency, qualifiers = {}) {
2415
+ const unitPrice = Number(rule.unit_price);
2416
+ const unit = 1 / Number(rule.unit_size);
2417
+ const amount = roundCharge(quantity * unitPrice * unit);
2418
+ var _rule_currency;
2419
+ return _extends({
2420
+ component: rule.component,
2421
+ quantity,
2422
+ pricingStatus: unitPrice === 0 ? 'free' : 'priced',
2423
+ unitPrice,
2424
+ unit,
2425
+ amount,
2426
+ currency: normalizeCurrency((_rule_currency = rule.currency) != null ? _rule_currency : fallbackCurrency)
2427
+ }, qualifiers, {
2428
+ rule
2429
+ });
2430
+ }
2431
+ function legacyPriceComponent(pricing, priceType, quantity, inputTokens) {
2432
+ const price = calculateModelPrice(pricing, priceType, quantity, inputTokens);
2433
+ return {
2434
+ component: priceType,
2435
+ quantity,
2436
+ pricingStatus: price.unitPrice === 0 ? 'free' : 'priced',
2437
+ unitPrice: price.unitPrice,
2438
+ unit: price.unit,
2439
+ amount: price.totalAmount,
2440
+ currency: normalizeCurrency(price.currency)
2441
+ };
2442
+ }
2443
+ function unpricedComponent(component, quantity, qualifiers = {}) {
2444
+ return _extends({
2445
+ component,
2446
+ quantity,
2447
+ pricingStatus: 'unpriced'
2448
+ }, qualifiers);
2449
+ }
2450
+ function tokenCount(value, name) {
2451
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0) {
2452
+ throw new Error(`${name} must be a finite non-negative integer`);
2453
+ }
2454
+ return value;
2455
+ }
2456
+ function nonNegativeQuantity(value, name) {
2457
+ if (!Number.isFinite(value) || value < 0) {
2458
+ throw new Error(`${name} must be a non-negative number`);
2459
+ }
2460
+ return value;
2461
+ }
2462
+ function resolveCacheWriteInputTokens(total, context) {
2463
+ if (!context.cacheWriteInputTokensByTtl) {
2464
+ return total > 0 ? [
2465
+ {
2466
+ quantity: total,
2467
+ cacheTtl: context.cacheWriteTtl
2468
+ }
2469
+ ] : [];
2470
+ }
2471
+ const cacheWrites = [
2472
+ '5m',
2473
+ '1h'
2474
+ ].map((cacheTtl)=>{
2475
+ var _context_cacheWriteInputTokensByTtl;
2476
+ var _context_cacheWriteInputTokensByTtl_cacheTtl;
2477
+ return {
2478
+ cacheTtl,
2479
+ quantity: tokenCount((_context_cacheWriteInputTokensByTtl_cacheTtl = (_context_cacheWriteInputTokensByTtl = context.cacheWriteInputTokensByTtl) == null ? void 0 : _context_cacheWriteInputTokensByTtl[cacheTtl]) != null ? _context_cacheWriteInputTokensByTtl_cacheTtl : 0, `cacheWriteInputTokensByTtl.${cacheTtl}`)
2480
+ };
2481
+ }).filter(({ quantity })=>quantity > 0);
2482
+ const detailedTotal = cacheWrites.reduce((sum, item)=>sum + item.quantity, 0);
2483
+ if (detailedTotal !== total) {
2484
+ throw new Error('Cache write token counts by TTL must equal cacheWriteInputTokens');
2485
+ }
2486
+ return cacheWrites;
2487
+ }
2488
+ function summarizeLLMPrice(currency, breakdown) {
2489
+ const hasUnpricedComponent = breakdown.some((item)=>item.pricingStatus === 'unpriced');
2490
+ const hasPaidComponent = breakdown.some((item)=>item.pricingStatus === 'priced');
2491
+ const currencies = new Set(breakdown.map((item)=>item.currency).filter((value)=>Boolean(value)).map(normalizeCurrency));
2492
+ if (currencies.size > 1) {
2493
+ throw new Error('LLM pricing calculation cannot mix currencies');
2494
+ }
2495
+ var _currencies_values_next_value;
2496
+ return {
2497
+ pricingStatus: hasUnpricedComponent ? 'unpriced' : hasPaidComponent ? 'priced' : 'free',
2498
+ totalAmount: Number(breakdown.reduce((total, item)=>{
2499
+ var _item_amount;
2500
+ return total + ((_item_amount = item.amount) != null ? _item_amount : 0);
2501
+ }, 0).toFixed(7)),
2502
+ currency: (_currencies_values_next_value = currencies.values().next().value) != null ? _currencies_values_next_value : normalizeCurrency(currency),
2503
+ breakdown
2504
+ };
2505
+ }
2506
+ function normalizeCurrency(currency) {
2507
+ return currency.trim().toUpperCase();
2508
+ }
2118
2509
 
2119
2510
  var AIModel_1;
2120
2511
  let AIModel = AIModel_1 = class AIModel {
@@ -2252,13 +2643,21 @@ let AIModel = AIModel_1 = class AIModel {
2252
2643
  ];
2253
2644
  }
2254
2645
  getModelProfile(model, credentials) {
2255
- var _modelSchema_model_properties, _modelSchema_features, _modelSchema_features1, _modelSchema_features2, _modelSchema_features3;
2646
+ var _modelSchema_model_properties, _modelSchema_features, _modelSchema_features1, _modelSchema_features2, _modelSchema_features3, _modelSchema_features4, _modelSchema_features5, _modelSchema_parameter_rules;
2256
2647
  const modelSchema = this.getModelSchema(model, credentials);
2257
- return modelSchema && {
2648
+ if (!modelSchema) return null;
2649
+ const profile = {
2258
2650
  maxInputTokens: (_modelSchema_model_properties = modelSchema.model_properties) == null ? void 0 : _modelSchema_model_properties.context_size,
2259
- toolCalling: ((_modelSchema_features = modelSchema.features) == null ? void 0 : _modelSchema_features.includes(ModelFeature.TOOL_CALL)) || ((_modelSchema_features1 = modelSchema.features) == null ? void 0 : _modelSchema_features1.includes(ModelFeature.MULTI_TOOL_CALL)) || ((_modelSchema_features2 = modelSchema.features) == null ? void 0 : _modelSchema_features2.includes(ModelFeature.STREAM_TOOL_CALL)),
2260
- structuredOutput: (_modelSchema_features3 = modelSchema.features) == null ? void 0 : _modelSchema_features3.includes(ModelFeature.STRUCTURED_OUTPUT)
2651
+ imageInputs: (_modelSchema_features = modelSchema.features) == null ? void 0 : _modelSchema_features.includes(ModelFeature.VISION),
2652
+ videoInputs: (_modelSchema_features1 = modelSchema.features) == null ? void 0 : _modelSchema_features1.includes(ModelFeature.VIDEO),
2653
+ toolCalling: ((_modelSchema_features2 = modelSchema.features) == null ? void 0 : _modelSchema_features2.includes(ModelFeature.TOOL_CALL)) || ((_modelSchema_features3 = modelSchema.features) == null ? void 0 : _modelSchema_features3.includes(ModelFeature.MULTI_TOOL_CALL)) || ((_modelSchema_features4 = modelSchema.features) == null ? void 0 : _modelSchema_features4.includes(ModelFeature.STREAM_TOOL_CALL)),
2654
+ structuredOutput: (_modelSchema_features5 = modelSchema.features) == null ? void 0 : _modelSchema_features5.includes(ModelFeature.STRUCTURED_OUTPUT)
2261
2655
  };
2656
+ const maxTokensRule = (_modelSchema_parameter_rules = modelSchema.parameter_rules) == null ? void 0 : _modelSchema_parameter_rules.find((rule)=>rule.name === 'max_tokens');
2657
+ if (maxTokensRule) {
2658
+ profile.maxOutputTokens = maxTokensRule.max;
2659
+ }
2660
+ return profile;
2262
2661
  }
2263
2662
  constructor(modelProvider, modelType){
2264
2663
  this.logger = new Logger(AIModel_1.name);
@@ -2398,7 +2797,55 @@ class LargeLanguageModel extends AIModel {
2398
2797
  _commonParameterRules(model) {
2399
2798
  return CommonParameterRules;
2400
2799
  }
2401
- calcResponseUsage(model, credentials, promptTokens, completionTokens, startedAt = this.startedAt) {
2800
+ calcResponseUsage(model, credentials, promptTokens, completionTokens, startedAt = this.startedAt, tokenUsage, pricingContext = {}) {
2801
+ var _this_getModelSchema;
2802
+ const resolvedTokenUsage = tokenUsage != null ? tokenUsage : {
2803
+ promptTokens,
2804
+ completionTokens,
2805
+ totalTokens: promptTokens + completionTokens
2806
+ };
2807
+ const pricing = (_this_getModelSchema = this.getModelSchema(model, credentials)) == null ? void 0 : _this_getModelSchema.pricing;
2808
+ if (pricing && !isModelUsagePricingConfig(pricing)) {
2809
+ const calculation = calculateLLMUsagePrice(pricing, resolvedTokenUsage, pricingContext);
2810
+ const promptBreakdown = calculation.breakdown.filter((item)=>[
2811
+ 'input',
2812
+ 'cache_read_input',
2813
+ 'cache_write_input'
2814
+ ].includes(item.component));
2815
+ const completionBreakdown = calculation.breakdown.filter((item)=>item.component === 'output');
2816
+ var _promptBreakdown_find;
2817
+ const promptRate = (_promptBreakdown_find = promptBreakdown.find((item)=>item.component === 'input')) != null ? _promptBreakdown_find : promptBreakdown[0];
2818
+ const completionRate = completionBreakdown[0];
2819
+ var _promptRate_unitPrice, _promptRate_unit, _completionRate_unitPrice, _completionRate_unit;
2820
+ return _extends({
2821
+ promptTokens,
2822
+ promptUnitPrice: (_promptRate_unitPrice = promptRate == null ? void 0 : promptRate.unitPrice) != null ? _promptRate_unitPrice : 0,
2823
+ promptPriceUnit: (_promptRate_unit = promptRate == null ? void 0 : promptRate.unit) != null ? _promptRate_unit : 0,
2824
+ promptPrice: Number(promptBreakdown.reduce((total, item)=>{
2825
+ var _item_amount;
2826
+ return total + ((_item_amount = item.amount) != null ? _item_amount : 0);
2827
+ }, 0).toFixed(7)),
2828
+ completionTokens,
2829
+ completionUnitPrice: (_completionRate_unitPrice = completionRate == null ? void 0 : completionRate.unitPrice) != null ? _completionRate_unitPrice : 0,
2830
+ completionPriceUnit: (_completionRate_unit = completionRate == null ? void 0 : completionRate.unit) != null ? _completionRate_unit : 0,
2831
+ completionPrice: Number(completionBreakdown.reduce((total, item)=>{
2832
+ var _item_amount;
2833
+ return total + ((_item_amount = item.amount) != null ? _item_amount : 0);
2834
+ }, 0).toFixed(7)),
2835
+ totalTokens: resolvedTokenUsage.totalTokens,
2836
+ totalPrice: calculation.totalAmount,
2837
+ currency: calculation.currency,
2838
+ latency: performance.now() - startedAt
2839
+ }, resolvedTokenUsage.cacheReadInputTokens ? {
2840
+ cacheReadInputTokens: resolvedTokenUsage.cacheReadInputTokens
2841
+ } : {}, resolvedTokenUsage.cacheWriteInputTokens ? {
2842
+ cacheWriteInputTokens: resolvedTokenUsage.cacheWriteInputTokens
2843
+ } : {}, {
2844
+ pricingStatus: calculation.pricingStatus,
2845
+ priceAuthority: 'catalog',
2846
+ pricingBreakdown: calculation.breakdown
2847
+ });
2848
+ }
2402
2849
  const promptPriceInfo = this.getPrice(model, credentials, PriceType.INPUT, promptTokens, promptTokens);
2403
2850
  const completionPriceInfo = this.getPrice(model, credentials, PriceType.OUTPUT, completionTokens, promptTokens);
2404
2851
  const totalPrice = Number((promptPriceInfo.totalAmount + completionPriceInfo.totalAmount).toFixed(7));
@@ -2415,32 +2862,50 @@ class LargeLanguageModel extends AIModel {
2415
2862
  totalTokens: promptTokens + completionTokens,
2416
2863
  totalPrice,
2417
2864
  currency: promptPriceInfo.currency,
2418
- latency: performance.now() - startedAt
2865
+ latency: performance.now() - startedAt,
2866
+ pricingStatus: totalPrice === 0 ? 'free' : 'priced',
2867
+ priceAuthority: 'catalog'
2419
2868
  };
2420
2869
  return usage;
2421
2870
  }
2422
- createHandleUsageCallbacks(copilot, model, credentials, handleLLMTokens) {
2871
+ createHandleUsageCallbacks(copilot, model, credentials, handleLLMTokens, pricingConfiguration = {}) {
2872
+ const pricingOptions = normalizeUsagePricingOptions(pricingConfiguration);
2873
+ var _pricingOptions_context;
2874
+ const basePricingContext = (_pricingOptions_context = pricingOptions.context) != null ? _pricingOptions_context : {};
2423
2875
  const runs = new Map();
2424
- const reportUsage = async (requestId, tokenUsage, startedAt, type)=>{
2425
- if (!handleLLMTokens || tokenUsage.totalTokens <= 0) {
2876
+ const reportUsage = async (requestId, tokenUsage, startedAt, pricingTime, type, output)=>{
2877
+ const pricingContext = _extends({}, basePricingContext, output && pricingOptions.resolveContext ? pricingOptions.resolveContext(output) : {}, {
2878
+ pricingTime
2879
+ });
2880
+ const normalizedTokenUsage = normalizeCacheTokenAccounting(tokenUsage, pricingContext);
2881
+ if (!handleLLMTokens || normalizedTokenUsage.totalTokens <= 0) {
2426
2882
  return;
2427
2883
  }
2428
- const usage = _extends({}, this.calcResponseUsage(model, credentials, tokenUsage.promptTokens, tokenUsage.completionTokens, startedAt), type ? {
2884
+ let usage = _extends({}, this.calcResponseUsage(model, credentials, normalizedTokenUsage.promptTokens, normalizedTokenUsage.completionTokens, startedAt, normalizedTokenUsage, _extends({}, pricingContext, {
2885
+ inputTokensIncludeCache: true
2886
+ })), type ? {
2429
2887
  type
2430
2888
  } : {});
2431
- usage.totalTokens = tokenUsage.totalTokens;
2889
+ const reportedPrice = output ? pricingOptions.resolveReportedPrice == null ? void 0 : pricingOptions.resolveReportedPrice.call(pricingOptions, output) : undefined;
2890
+ if (reportedPrice) {
2891
+ usage = applyProviderReportedPrice(usage, reportedPrice);
2892
+ } else if (pricingOptions.reportedPriceRequired) {
2893
+ usage = markUsagePriceUnpriced(usage, 'provider');
2894
+ }
2895
+ usage.totalTokens = normalizedTokenUsage.totalTokens;
2432
2896
  await handleLLMTokens({
2433
2897
  copilot,
2434
2898
  model,
2435
2899
  requestId,
2436
2900
  usage,
2437
- tokenUsed: tokenUsage.totalTokens
2901
+ tokenUsed: normalizedTokenUsage.totalTokens
2438
2902
  });
2439
2903
  };
2440
2904
  const callback = BaseCallbackHandler.fromMethods({
2441
2905
  handleLLMStart: (_llm, prompts, runId)=>{
2442
2906
  runs.set(runId, {
2443
2907
  startedAt: performance.now(),
2908
+ pricingTime: new Date(),
2444
2909
  prompts,
2445
2910
  completion: ''
2446
2911
  });
@@ -2456,11 +2921,11 @@ class LargeLanguageModel extends AIModel {
2456
2921
  runs.delete(runId);
2457
2922
  const resolved = resolveTokenUsageWithAuthority(output);
2458
2923
  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);
2924
+ var _run_startedAt, _run_pricingTime;
2925
+ await reportUsage(runId, resolved.usage, (_run_startedAt = run == null ? void 0 : run.startedAt) != null ? _run_startedAt : performance.now(), (_run_pricingTime = run == null ? void 0 : run.pricingTime) != null ? _run_pricingTime : new Date(), resolved.type, output);
2461
2926
  } 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');
2927
+ var _run_startedAt1, _run_pricingTime1;
2928
+ 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(), (_run_pricingTime1 = run == null ? void 0 : run.pricingTime) != null ? _run_pricingTime1 : new Date(), 'estimated', output);
2464
2929
  }
2465
2930
  },
2466
2931
  handleLLMError: async (error, runId)=>{
@@ -2469,8 +2934,8 @@ class LargeLanguageModel extends AIModel {
2469
2934
  if (!(run == null ? void 0 : run.completion) && !isAbortError(error)) {
2470
2935
  return;
2471
2936
  }
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');
2937
+ var _run_startedAt, _run_pricingTime;
2938
+ 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(), (_run_pricingTime = run == null ? void 0 : run.pricingTime) != null ? _run_pricingTime : new Date(), 'estimated');
2474
2939
  }
2475
2940
  });
2476
2941
  callback.awaitHandlers = true;
@@ -2613,6 +3078,37 @@ class LargeLanguageModel extends AIModel {
2613
3078
  }
2614
3079
  }
2615
3080
  _a = LargeLanguageModel;
3081
+ function normalizeUsagePricingOptions(configuration) {
3082
+ if ('context' in configuration || 'resolveContext' in configuration || 'resolveReportedPrice' in configuration || 'reportedPriceRequired' in configuration) {
3083
+ return configuration;
3084
+ }
3085
+ return {
3086
+ context: configuration
3087
+ };
3088
+ }
3089
+ function applyProviderReportedPrice(usage, reportedPrice) {
3090
+ var _reportedPrice_currency;
3091
+ const amount = Number(reportedPrice.amount);
3092
+ const currency = (_reportedPrice_currency = reportedPrice.currency) == null ? void 0 : _reportedPrice_currency.trim();
3093
+ if (!Number.isFinite(amount) || amount < 0 || !currency) {
3094
+ throw new Error('Provider-reported price requires a non-negative amount and currency');
3095
+ }
3096
+ return _extends({}, usage, {
3097
+ totalPrice: amount,
3098
+ currency: currency.toUpperCase(),
3099
+ pricingStatus: amount === 0 ? 'free' : 'priced',
3100
+ priceAuthority: 'provider',
3101
+ pricingBreakdown: undefined
3102
+ });
3103
+ }
3104
+ function markUsagePriceUnpriced(usage, priceAuthority) {
3105
+ return _extends({}, usage, {
3106
+ totalPrice: 0,
3107
+ pricingStatus: 'unpriced',
3108
+ priceAuthority,
3109
+ pricingBreakdown: undefined
3110
+ });
3111
+ }
2616
3112
  function estimateFallbackUsage(prompts, completion) {
2617
3113
  if (!prompts) {
2618
3114
  return {
@@ -2669,16 +3165,25 @@ function calcTokenUsage(output) {
2669
3165
  completionTokens: 0,
2670
3166
  totalTokens: 0
2671
3167
  };
3168
+ let cacheReadInputTokens = 0;
3169
+ let cacheWriteInputTokens = 0;
2672
3170
  (_output_generations = output.generations) == null ? void 0 : _output_generations.forEach((generation)=>{
2673
3171
  generation.forEach((item)=>{
2674
3172
  const message = item.message;
2675
3173
  if (message.usage_metadata) {
3174
+ var _message_usage_metadata_input_token_details, _message_usage_metadata_input_token_details1;
2676
3175
  tokenUsage.promptTokens += message.usage_metadata.input_tokens;
2677
3176
  tokenUsage.completionTokens += message.usage_metadata.output_tokens;
2678
3177
  tokenUsage.totalTokens += message.usage_metadata.total_tokens;
3178
+ var _message_usage_metadata_input_token_details_cache_read;
3179
+ cacheReadInputTokens += (_message_usage_metadata_input_token_details_cache_read = (_message_usage_metadata_input_token_details = message.usage_metadata.input_token_details) == null ? void 0 : _message_usage_metadata_input_token_details.cache_read) != null ? _message_usage_metadata_input_token_details_cache_read : 0;
3180
+ var _message_usage_metadata_input_token_details_cache_creation;
3181
+ cacheWriteInputTokens += (_message_usage_metadata_input_token_details_cache_creation = (_message_usage_metadata_input_token_details1 = message.usage_metadata.input_token_details) == null ? void 0 : _message_usage_metadata_input_token_details1.cache_creation) != null ? _message_usage_metadata_input_token_details_cache_creation : 0;
2679
3182
  }
2680
3183
  });
2681
3184
  });
3185
+ if (cacheReadInputTokens > 0) tokenUsage.cacheReadInputTokens = cacheReadInputTokens;
3186
+ if (cacheWriteInputTokens > 0) tokenUsage.cacheWriteInputTokens = cacheWriteInputTokens;
2682
3187
  return tokenUsage;
2683
3188
  }
2684
3189
  function resolveTokenUsage(output) {
@@ -2725,15 +3230,36 @@ function normalizeTokenUsage(candidate) {
2725
3230
  if (promptTokens === 0 && completionTokens === 0 && totalTokens === 0) {
2726
3231
  return null;
2727
3232
  }
2728
- return {
3233
+ var _candidate_cacheReadInputTokens;
3234
+ const cacheReadInputTokens = (_candidate_cacheReadInputTokens = candidate.cacheReadInputTokens) != null ? _candidate_cacheReadInputTokens : 0;
3235
+ var _candidate_cacheWriteInputTokens;
3236
+ const cacheWriteInputTokens = (_candidate_cacheWriteInputTokens = candidate.cacheWriteInputTokens) != null ? _candidate_cacheWriteInputTokens : 0;
3237
+ if (!isValidTokenCount(cacheReadInputTokens) || !isValidTokenCount(cacheWriteInputTokens)) {
3238
+ return null;
3239
+ }
3240
+ return _extends({
2729
3241
  promptTokens,
2730
3242
  completionTokens,
2731
3243
  totalTokens
2732
- };
3244
+ }, cacheReadInputTokens > 0 ? {
3245
+ cacheReadInputTokens
3246
+ } : {}, cacheWriteInputTokens > 0 ? {
3247
+ cacheWriteInputTokens
3248
+ } : {});
2733
3249
  }
2734
3250
  function isValidTokenCount(value) {
2735
3251
  return value === undefined || Number.isFinite(value) && value >= 0;
2736
3252
  }
3253
+ function normalizeCacheTokenAccounting(tokenUsage, context) {
3254
+ if (context.inputTokensIncludeCache !== false) return tokenUsage;
3255
+ var _tokenUsage_cacheReadInputTokens, _tokenUsage_cacheWriteInputTokens;
3256
+ const cacheTokens = ((_tokenUsage_cacheReadInputTokens = tokenUsage.cacheReadInputTokens) != null ? _tokenUsage_cacheReadInputTokens : 0) + ((_tokenUsage_cacheWriteInputTokens = tokenUsage.cacheWriteInputTokens) != null ? _tokenUsage_cacheWriteInputTokens : 0);
3257
+ if (!cacheTokens) return tokenUsage;
3258
+ return _extends({}, tokenUsage, {
3259
+ promptTokens: tokenUsage.promptTokens + cacheTokens,
3260
+ totalTokens: tokenUsage.totalTokens + cacheTokens
3261
+ });
3262
+ }
2737
3263
  /**
2738
3264
  * @deprecated use calcTokenUsage
2739
3265
  */ function sumTokenUsage(output) {
@@ -2758,6 +3284,19 @@ function isValidTokenCount(value) {
2758
3284
  let payload = job.data;
2759
3285
  if (payload.phase === 'succeeded' && payload.result !== undefined) return payload.result;
2760
3286
  if (payload.phase === 'failed') throw new Error(payload.errorCode || 'Provider generation task failed');
3287
+ if (!payload.modelAccess && options.provider.resolveModelAccess) {
3288
+ const modelAccess = await options.provider.resolveModelAccess({
3289
+ requestId: payload.requestId,
3290
+ model: payload.model,
3291
+ operation: payload.operation,
3292
+ modality: payload.modality,
3293
+ pricingDimensions: payload.pricingDimensions,
3294
+ startedAt: payload.startedAt
3295
+ });
3296
+ payload = await checkpoint(job, _extends({}, payload, {
3297
+ modelAccess
3298
+ }));
3299
+ }
2761
3300
  if (!payload.pricingSnapshot) {
2762
3301
  const pricingSnapshot = options.provider.resolvePricingSnapshot ? await options.provider.resolvePricingSnapshot({
2763
3302
  model: payload.model,
@@ -2832,7 +3371,7 @@ async function reportTerminalUsage(job, payload, metrics, provider) {
2832
3371
  pricingSnapshot: payload.pricingSnapshot,
2833
3372
  metrics,
2834
3373
  recordedAt: new Date().toISOString()
2835
- });
3374
+ }, payload.modelAccess);
2836
3375
  return checkpoint(job, _extends({}, payload, {
2837
3376
  usageReported: true
2838
3377
  }));
@@ -5195,4 +5734,4 @@ const EvolutionRuntimeCapability = createRuntimeCapability('platform.agent-evolu
5195
5734
  description: 'Ingest learning signals and resolve immutable capability versions for domain runtimes.'
5196
5735
  });
5197
5736
 
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 };
5737
+ export { ACCOUNT_BINDING_PERMISSION_SERVICE_TOKEN, AGENT_CHAT_DISPATCH_ERROR_STEER_TARGET_NOT_RUNNING, AGENT_CHAT_DISPATCH_MESSAGE_TYPE, AGENT_MIDDLEWARE_STRATEGY, AIModel, 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, calculateLLMUsagePrice, 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 };