@xpert-ai/plugin-sdk 3.17.0 → 3.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,6 +180,10 @@ const KnowledgebaseDocumentsRuntimeCapability = createRuntimeCapability('platfor
180
180
  description: 'Upload, import, create, process, inspect, and delete persistent knowledgebase documents.'
181
181
  });
182
182
 
183
+ const KnowledgeDocumentVisualAssetsRuntimeCapability = createRuntimeCapability('platform.knowledgebase.visual-assets', {
184
+ description: 'Issue execution-scoped logical KnowledgeDocument image paths and inject validated images without exposing host storage paths.'
185
+ });
186
+
183
187
  const ActorTokenRuntimeCapability = createRuntimeCapability('platform.actor-token', {
184
188
  description: 'Mint a short-lived host-issued actor bearer token for outbound API calls.'
185
189
  });
@@ -333,6 +337,7 @@ exports.BaseTool = BaseTool;
333
337
  exports.BaseToolset = BaseToolset;
334
338
  exports.BuiltinToolset = BuiltinToolset;
335
339
  exports.DefaultRuntimeCapabilityRegistry = DefaultRuntimeCapabilityRegistry;
340
+ exports.KnowledgeDocumentVisualAssetsRuntimeCapability = KnowledgeDocumentVisualAssetsRuntimeCapability;
336
341
  exports.KnowledgebaseDocumentsRuntimeCapability = KnowledgebaseDocumentsRuntimeCapability;
337
342
  exports.KnowledgebaseProvisioningRuntimeCapability = KnowledgebaseProvisioningRuntimeCapability;
338
343
  exports.KnowledgebaseRuntimeCapability = KnowledgebaseRuntimeCapability;
@@ -178,6 +178,10 @@ const KnowledgebaseDocumentsRuntimeCapability = createRuntimeCapability('platfor
178
178
  description: 'Upload, import, create, process, inspect, and delete persistent knowledgebase documents.'
179
179
  });
180
180
 
181
+ const KnowledgeDocumentVisualAssetsRuntimeCapability = createRuntimeCapability('platform.knowledgebase.visual-assets', {
182
+ description: 'Issue execution-scoped logical KnowledgeDocument image paths and inject validated images without exposing host storage paths.'
183
+ });
184
+
181
185
  const ActorTokenRuntimeCapability = createRuntimeCapability('platform.actor-token', {
182
186
  description: 'Mint a short-lived host-issued actor bearer token for outbound API calls.'
183
187
  });
@@ -325,4 +329,4 @@ function normalizeOptionalString(value) {
325
329
  return normalized || undefined;
326
330
  }
327
331
 
328
- export { ActorTokenRuntimeCapability as A, BaseTool as B, DefaultRuntimeCapabilityRegistry as D, KnowledgebaseDocumentsRuntimeCapability as K, ModelProviderBuiltinToolset as M, SANDBOX_JOB_ERROR_CODES as S, WORKSPACE_FILES_SOURCE as W, XPERT_RUNTIME_CAPABILITIES_TOKEN as X, ArtifactsRuntimeCapability as a, BaseToolset as b, createRuntimeCapability as c, BuiltinToolset as d, KnowledgebaseProvisioningRuntimeCapability as e, KnowledgebaseRuntimeCapability as f, SANDBOX_JOB_PROGRESS_PREFIX as g, SandboxJobRuntimeError as h, SandboxJobsRuntimeCapability as i, WorkspaceFilesRuntimeCapability as j, isSandboxJobRuntimeError as k };
332
+ export { ActorTokenRuntimeCapability as A, BaseTool as B, DefaultRuntimeCapabilityRegistry as D, KnowledgeDocumentVisualAssetsRuntimeCapability as K, ModelProviderBuiltinToolset as M, SANDBOX_JOB_ERROR_CODES as S, WORKSPACE_FILES_SOURCE as W, XPERT_RUNTIME_CAPABILITIES_TOKEN as X, ArtifactsRuntimeCapability as a, BaseToolset as b, createRuntimeCapability as c, BuiltinToolset as d, KnowledgebaseDocumentsRuntimeCapability as e, KnowledgebaseProvisioningRuntimeCapability as f, KnowledgebaseRuntimeCapability as g, SANDBOX_JOB_PROGRESS_PREFIX as h, SandboxJobRuntimeError as i, SandboxJobsRuntimeCapability as j, WorkspaceFilesRuntimeCapability as k, isSandboxJobRuntimeError as l };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-sdk",
3
- "version": "3.17.0",
3
+ "version": "3.17.2",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@langchain/openai": "0.6.9",
20
- "@xpert-ai/contracts": "3.17.0",
20
+ "@xpert-ai/contracts": "3.17.2",
21
21
  "express": "^4.22.1",
22
22
  "js-tiktoken": "^1.0.21"
23
23
  },
@@ -3,7 +3,7 @@ import { BaseLanguageModel } from '@langchain/core/language_models/base';
3
3
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
4
  import type { Runtime as LangGraphRuntime } from '@langchain/langgraph';
5
5
  import type { BaseMessage } from '@langchain/core/messages';
6
- import { ICopilotModel, IXpertAgentExecution, JSONValue, ModelUsagePricingSnapshot, ModelUsageReport, ModelUsageReportResult, ModelUsagePricingContext, TSandboxConfigurable } from '@xpert-ai/contracts';
6
+ import { ICopilotModel, IModelAccessResolution, IXpertAgentExecution, JSONValue, ModelUsagePricingSnapshot, ModelUsageReport, ModelUsageReportResult, ModelUsagePricingContext, TSandboxConfigurable } from '@xpert-ai/contracts';
7
7
  import { Subscriber } from 'rxjs';
8
8
  import { AIGCModelClient, AsyncAIGCModelClient, IRerank, TLLMUsage } from '../../ai-model/types';
9
9
  import type { RuntimeCapabilityRegistry } from '../../core';
@@ -71,6 +71,9 @@ export type AgentMiddlewareCreateModelClientOptions = {
71
71
  /** `observe` reads an existing asynchronous task and must not consume generation quota. */
72
72
  purpose?: 'invoke' | 'observe';
73
73
  };
74
+ export type AgentMiddlewareModelAccessContext = ModelUsagePricingContext & {
75
+ requestId: string;
76
+ };
74
77
  export type AgentMiddlewareModelProviderConnection = {
75
78
  /** Stable host-owned model provider configuration boundary. */
76
79
  providerScopeId: string;
@@ -81,10 +84,12 @@ export type AgentMiddlewareModelProviderConnection = {
81
84
  provider: string;
82
85
  baseURL: string;
83
86
  authorization: string;
87
+ /** Resolve and freeze the host-owned Direct/Grant access decision before provider invocation. */
88
+ resolveModelAccess?: (context: AgentMiddlewareModelAccessContext) => Promise<IModelAccessResolution>;
84
89
  /** Resolve the model YAML price rule and freeze it for one invocation. */
85
90
  resolvePricingSnapshot?: (context: ModelUsagePricingContext) => Promise<ModelUsagePricingSnapshot>;
86
91
  /** Persist final authoritative usage and calculate its charge exactly once. */
87
- reportUsage(report: ModelUsageReport): Promise<ModelUsageReportResult>;
92
+ reportUsage(report: ModelUsageReport, modelAccess?: IModelAccessResolution): Promise<ModelUsageReportResult>;
88
93
  };
89
94
  export type AgentMiddlewareRuntimeScope = {
90
95
  tenantId?: string | null;
@@ -8,6 +8,10 @@ export interface IAIModelProviderStrategy {
8
8
  /**
9
9
  * Provider metadata
10
10
  */
11
+ /**
12
+ * Stable provider identifier from the provider schema.
13
+ */
14
+ readonly name: string;
11
15
  /**
12
16
  * Validate whether the credentials are valid
13
17
  */
@@ -35,7 +39,7 @@ export interface IAIModelProviderStrategy {
35
39
  /**
36
40
  * Return the defined provider models (metadata)
37
41
  */
38
- getProviderModels?(modelType?: AiModelTypeEnum, onlyActive?: boolean): ProviderModel[];
42
+ getProviderModels(modelType?: AiModelTypeEnum, onlyActive?: boolean): ProviderModel[];
39
43
  getProviderSchema(): IAiProviderEntity;
40
44
  getProviderServerPath(): string;
41
45
  getModelManager<T extends AIModel>(modelType: AiModelTypeEnum): T;
@@ -1,6 +1,7 @@
1
1
  export * from './ai-model-provider.interface';
2
2
  export * from './ai-model-provider.decorator';
3
3
  export * from './ai-model-provider.registry';
4
+ export * from './ai-model';
4
5
  export * from './abstract-provider';
5
6
  export * from './types';
6
7
  export * from './llm';
@@ -1,4 +1,4 @@
1
- import { AIModelEntity, ICopilot, ILLMUsage, ParameterRule, TTokenUsage } from '@xpert-ai/contracts';
1
+ import { AIModelEntity, ICopilot, ILLMUsage, LLMPriceContext, LLMReportedPrice, ParameterRule, TTokenUsage } from '@xpert-ai/contracts';
2
2
  import { Logger } from '@nestjs/common';
3
3
  import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
4
4
  import { LLMResult } from '@langchain/core/outputs';
@@ -8,6 +8,13 @@ export type CommonChatModelParameters = {
8
8
  temperature: number;
9
9
  maxRetries?: number | null;
10
10
  };
11
+ export type LLMUsagePricingOptions = {
12
+ context?: LLMPriceContext;
13
+ resolveContext?: (output: LLMResult) => LLMPriceContext;
14
+ resolveReportedPrice?: (output: LLMResult) => LLMReportedPrice | undefined;
15
+ reportedPriceRequired?: boolean;
16
+ };
17
+ export type LLMUsagePricingConfiguration = LLMPriceContext | LLMUsagePricingOptions;
11
18
  export declare class LLMUsage implements ILLMUsage {
12
19
  /**
13
20
  * Model class for llm usage.
@@ -33,8 +40,8 @@ export declare abstract class LargeLanguageModel extends AIModel {
33
40
  #private;
34
41
  protected startedAt: DOMHighResTimeStamp;
35
42
  protected _commonParameterRules(model: string): ParameterRule[];
36
- protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number, startedAt?: number): ILLMUsage;
37
- createHandleUsageCallbacks(copilot: ICopilot, model: string, credentials: any, handleLLMTokens: TChatModelOptions['handleLLMTokens']): {
43
+ protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number, startedAt?: number, tokenUsage?: TTokenUsage, pricingContext?: LLMPriceContext): ILLMUsage;
44
+ createHandleUsageCallbacks(copilot: ICopilot, model: string, credentials: any, handleLLMTokens: TChatModelOptions['handleLLMTokens'], pricingConfiguration?: LLMUsagePricingConfiguration): {
38
45
  name: string;
39
46
  lc_serializable: boolean;
40
47
  readonly lc_namespace: ["langchain_core", "callbacks", string];
@@ -1,4 +1,4 @@
1
- import { type ModelUsageModality, type ModelUsageOperation, type ModelUsagePricingDimensions, type ModelUsagePricingSnapshot } from '@xpert-ai/contracts';
1
+ import { type IModelAccessResolution, type ModelUsageModality, type ModelUsageOperation, type ModelUsagePricingDimensions, type ModelUsagePricingSnapshot } from '@xpert-ai/contracts';
2
2
  import type { AgentMiddlewareModelProviderConnection } from '../agent/middleware/runtime';
3
3
  import type { ManagedQueueJob } from '../managed-queue';
4
4
  import type { AIGCModelObservation, AsyncAIGCModelClient } from './types/aigc';
@@ -16,6 +16,7 @@ export type AsyncAIGCManagedJobPayload<TInput, TResult> = {
16
16
  startedAt: string;
17
17
  providerRequestId?: string;
18
18
  providerState?: AIGCModelObservation['state'];
19
+ modelAccess?: IModelAccessResolution;
19
20
  pricingSnapshot?: ModelUsagePricingSnapshot;
20
21
  usageReported?: boolean;
21
22
  result?: TResult;
@@ -1,5 +1,6 @@
1
- import { type ModelUsagePricingSnapshot, type ModelUsageMetric, type ModelUsagePriceRule, type ModelUsagePricingConfig, type ModelUsagePricingContext, type ModelUsagePricingStatus, PriceConfig, PriceInfo, PriceType } from '@xpert-ai/contracts';
1
+ import { type LLMPriceCalculation, type LLMPriceContext, type ModelUsagePricingSnapshot, type ModelUsageMetric, type ModelUsagePriceRule, type ModelUsagePricingConfig, type ModelUsagePricingContext, type ModelUsagePricingStatus, PriceConfig, PriceInfo, PriceType, type TTokenUsage } from '@xpert-ai/contracts';
2
2
  export declare function calculateModelPrice(pricing: PriceConfig, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
3
+ export declare function calculateLLMUsagePrice(pricing: PriceConfig, usage: TTokenUsage, context?: LLMPriceContext): LLMPriceCalculation;
3
4
  export type ModelUsageChargeCalculation = {
4
5
  pricingStatus: ModelUsagePricingStatus;
5
6
  pricingRule?: ModelUsagePriceRule;
@@ -1,11 +1,15 @@
1
1
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ModelUsagePricingSnapshot, ModelUsagePricingContext, ParameterType, PriceInfo, PriceType } from '@xpert-ai/contracts';
2
+ import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ModelUsageReport, ModelUsagePricingContext, ModelUsagePricingSnapshot, ParameterRule, ParameterType, PriceInfo, PriceType } from '@xpert-ai/contracts';
3
3
  export type TModelUsageType = 'estimated';
4
4
  export type TLLMUsage = ILLMUsage & {
5
5
  type?: TModelUsageType;
6
6
  };
7
7
  export type TChatModelOptions = {
8
8
  modelProperties: Record<string, any>;
9
+ /** Final authoritative usage for non-LLM model clients. */
10
+ handleModelUsage?: (report: ModelUsageReport) => void | Promise<void>;
11
+ /** Freeze the active usage price rules at invocation start. */
12
+ resolveUsagePricingSnapshot?: (context: ModelUsagePricingContext) => ModelUsagePricingSnapshot | Promise<ModelUsagePricingSnapshot>;
9
13
  handleLLMTokens: (input: {
10
14
  copilot: ICopilot;
11
15
  model?: string;
@@ -22,6 +26,7 @@ export interface IAIModel {
22
26
  validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
23
27
  getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
24
28
  predefinedModels(): AIModelEntity[];
29
+ getParameterRules(model: string, credentials: Record<string, string>): ParameterRule[];
25
30
  getUsagePricingSnapshot(model: string, credentials: Record<string, any>, context: ModelUsagePricingContext): ModelUsagePricingSnapshot;
26
31
  getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
27
32
  }
@@ -1,5 +1,6 @@
1
1
  export * from './knowledgebase';
2
2
  export * from './knowledgebase-documents';
3
+ export * from './knowledge-document-visual-assets';
3
4
  export * from './actor-token';
4
5
  export * from './artifacts';
5
6
  export * from './workspace-files';
@@ -0,0 +1,78 @@
1
+ import type { WorkspacePortableFileReference } from './workspace-files';
2
+ export type KnowledgeDocumentVisualCandidateReason = 'same_block' | 'same_chunk' | 'same_page' | 'adjacent_page' | 'visual_summary_match' | 'visual_only_fallback';
3
+ export type KnowledgeDocumentVisualTextAnchor = {
4
+ page?: number;
5
+ chunkId?: string;
6
+ sourceBlockIds?: string[];
7
+ };
8
+ export type KnowledgeDocumentVisualBusinessScope = {
9
+ namespace: 'bom.requirement-evidence';
10
+ caseId: string;
11
+ baselineId: string;
12
+ runId: string;
13
+ sourceDocumentId: string;
14
+ };
15
+ export type KnowledgeDocumentVisualCandidateRequest = {
16
+ knowledgebaseId: string;
17
+ knowledgeDocumentId: string;
18
+ query: string;
19
+ textAnchors: KnowledgeDocumentVisualTextAnchor[];
20
+ maxAssets: number;
21
+ businessScope: KnowledgeDocumentVisualBusinessScope;
22
+ };
23
+ export type KnowledgeDocumentVisualCandidate = {
24
+ /**
25
+ * Execution-scoped logical path returned by a governed KnowledgeDocument search. This is not a
26
+ * host filesystem path and can only be resolved again by the knowledgebase image viewer.
27
+ */
28
+ filePath: string;
29
+ knowledgeDocumentId: string;
30
+ sourceDocumentId: string;
31
+ page?: number;
32
+ chunkId?: string;
33
+ sourceBlockIds: string[];
34
+ visualAssetId: string;
35
+ candidateReason: KnowledgeDocumentVisualCandidateReason;
36
+ summary?: string;
37
+ };
38
+ export type KnowledgeDocumentVisualCandidateResult = {
39
+ candidates: KnowledgeDocumentVisualCandidate[];
40
+ warnings: string[];
41
+ };
42
+ export type KnowledgeDocumentViewImagesInput = {
43
+ filePaths: string[];
44
+ };
45
+ export type KnowledgeDocumentViewedImage = Omit<KnowledgeDocumentVisualCandidate, 'filePath'> & {
46
+ index: number;
47
+ mimeType: 'image/png' | 'image/jpeg' | 'image/webp';
48
+ size: number;
49
+ width?: number;
50
+ height?: number;
51
+ sha256: string;
52
+ };
53
+ /**
54
+ * Server-only materialization data used to create an immutable ArtifactVersion.
55
+ *
56
+ * This value is returned through the in-process runtime capability and must not
57
+ * be copied into ToolMessage content or persisted chat metadata.
58
+ */
59
+ export type KnowledgeDocumentPreparedImageArtifact = {
60
+ index: number;
61
+ fileName: string;
62
+ workspaceFileRef: WorkspacePortableFileReference;
63
+ };
64
+ export type KnowledgeDocumentViewImagesResult = {
65
+ batchRef: string;
66
+ images: KnowledgeDocumentViewedImage[];
67
+ artifactInputs: KnowledgeDocumentPreparedImageArtifact[];
68
+ };
69
+ export type KnowledgeDocumentVisualImagePayload = KnowledgeDocumentViewedImage & {
70
+ dataBase64: string;
71
+ };
72
+ export interface KnowledgeDocumentVisualAssetsApi {
73
+ issueCandidates(input: KnowledgeDocumentVisualCandidateRequest): Promise<KnowledgeDocumentVisualCandidateResult>;
74
+ prepareImages(input: KnowledgeDocumentViewImagesInput): Promise<KnowledgeDocumentViewImagesResult>;
75
+ consumeImageBatch(batchRef: string): Promise<KnowledgeDocumentVisualImagePayload[]>;
76
+ discardImageBatch(batchRef: string): Promise<void>;
77
+ }
78
+ export declare const KnowledgeDocumentVisualAssetsRuntimeCapability: import("../../core/runtime-capability").RuntimeCapabilityKey<KnowledgeDocumentVisualAssetsApi>;