@xpert-ai/contracts 3.16.0 → 3.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/index.cjs.js +197 -35
  2. package/index.esm.js +185 -33
  3. package/package.json +1 -1
  4. package/src/agent/ai-model.d.ts +4 -1
  5. package/src/agent/graph.d.ts +2 -0
  6. package/src/ai/ai-model.model.d.ts +6 -1
  7. package/src/ai/evolution/candidate.d.ts +67 -0
  8. package/src/ai/evolution/capability-version.d.ts +45 -0
  9. package/src/ai/evolution/evaluation.d.ts +93 -0
  10. package/src/ai/evolution/example.d.ts +42 -0
  11. package/src/ai/evolution/experience.d.ts +21 -0
  12. package/src/ai/evolution/governance.d.ts +87 -0
  13. package/src/ai/evolution/index.d.ts +11 -0
  14. package/src/ai/evolution/learning-event.d.ts +69 -0
  15. package/src/ai/evolution/provider.d.ts +30 -0
  16. package/src/ai/evolution/release.d.ts +144 -0
  17. package/src/ai/evolution/runtime.d.ts +81 -0
  18. package/src/ai/evolution/target.d.ts +83 -0
  19. package/src/ai/index.d.ts +3 -0
  20. package/src/ai/knowledge-doc-chunk.model.d.ts +143 -0
  21. package/src/ai/knowledge-doc.model.d.ts +53 -4
  22. package/src/ai/knowledge-filter.model.d.ts +92 -0
  23. package/src/ai/knowledge-retrieval-log.model.d.ts +16 -0
  24. package/src/ai/knowledgebase-task.model.d.ts +3 -1
  25. package/src/ai/knowledgebase.model.d.ts +6 -0
  26. package/src/ai/membership.model.d.ts +40 -7
  27. package/src/ai/model-gateway.model.d.ts +5 -0
  28. package/src/ai/model-usage.model.d.ts +163 -0
  29. package/src/ai/role-permissions.d.ts +4 -1
  30. package/src/ai/xpert-agent-execution.model.d.ts +2 -0
  31. package/src/ai/xpert.model.d.ts +23 -11
  32. package/src/plugin.d.ts +4 -0
  33. package/src/tenant.model.d.ts +1 -1
  34. package/src/view-extension/model.d.ts +12 -1
@@ -11,6 +11,134 @@ export type TDocumentAsset = {
11
11
  order?: number;
12
12
  altText?: string;
13
13
  };
14
+ /** Stable, provider-neutral layout categories understood by the preview UI. */
15
+ export type DocumentAnalysisBlockType = 'text' | 'title' | 'table' | 'image' | 'formula' | 'header' | 'footer' | 'footnote' | 'page-number' | 'seal' | 'other';
16
+ /** Rectangle in the transformer-reported page coordinate system; values are not normalized to 0..1. */
17
+ export type DocumentAnalysisBounds = {
18
+ x: number;
19
+ y: number;
20
+ width: number;
21
+ height: number;
22
+ };
23
+ /** Polygon vertex in the transformer-reported page coordinate system. */
24
+ export type DocumentAnalysisPoint = {
25
+ x: number;
26
+ y: number;
27
+ };
28
+ /**
29
+ * Provider-neutral page-layout metadata emitted by a document transformer before text splitting.
30
+ * Coordinates use the top-left of the recognized page as their origin.
31
+ */
32
+ export type DocumentLayoutMetadata = {
33
+ schemaVersion: 1;
34
+ /** Global, 1-based source-document page number, including documents converted in batches. */
35
+ page: number;
36
+ /** Provider-reported page dimensions used to project bounds over the rendered source page. */
37
+ pageWidth: number;
38
+ pageHeight: number;
39
+ /** Stable identifier and reading order before downstream text splitting. */
40
+ blockId: string;
41
+ order: number;
42
+ type: DocumentAnalysisBlockType;
43
+ providerType?: string;
44
+ providerSubType?: string;
45
+ bounds?: DocumentAnalysisBounds;
46
+ polygon?: DocumentAnalysisPoint[];
47
+ /** Optional archived image/table asset associated with this exact layout block. */
48
+ asset?: TDocumentAsset;
49
+ /** Lossless provider payload retained for inspection; consumers must not assume its schema. */
50
+ raw?: Record<string, unknown>;
51
+ };
52
+ /** Provider-neutral description of the structured document produced by a transformer. */
53
+ export type DocumentAnalysisMetadata = {
54
+ schemaVersion: 1;
55
+ provider: string;
56
+ engine?: string;
57
+ pageCount?: number;
58
+ coordinateSystem: 'page-top-left';
59
+ markdownAsset?: TDocumentAsset;
60
+ /** Provider-neutral page/block payload used to materialize the protected analysis preview. */
61
+ analysisAsset?: TDocumentAsset;
62
+ /** Durable offset map from the merged Markdown back to source pages and layout blocks. */
63
+ sourceMapAsset?: TDocumentAsset;
64
+ rawAssets?: TDocumentAsset[];
65
+ };
66
+ /** One source block archived before the converter merges layout fragments into Markdown. */
67
+ export type DocumentAnalysisSourceBlock = {
68
+ id: string;
69
+ order: number;
70
+ type: DocumentAnalysisBlockType;
71
+ providerType?: string;
72
+ providerSubType?: string;
73
+ markdown: string;
74
+ bounds?: DocumentAnalysisBounds;
75
+ polygon?: DocumentAnalysisPoint[];
76
+ asset?: TDocumentAsset;
77
+ raw?: Record<string, unknown>;
78
+ };
79
+ /** Provider-neutral page record stored by a document converter for later preview materialization. */
80
+ export type DocumentAnalysisSourcePage = {
81
+ schemaVersion: 1;
82
+ page: number;
83
+ width: number;
84
+ height: number;
85
+ blocks: DocumentAnalysisSourceBlock[];
86
+ };
87
+ /** File payload referenced by `DocumentAnalysisMetadata.analysisAsset`. */
88
+ export type DocumentAnalysisSource = {
89
+ schemaVersion: 1;
90
+ pages: DocumentAnalysisSourcePage[];
91
+ };
92
+ /** A character interval in merged Markdown and its corresponding source-document range. */
93
+ export type DocumentMarkdownSourceMapEntry = {
94
+ startOffset: number;
95
+ endOffset: number;
96
+ pageStart: number;
97
+ pageEnd: number;
98
+ blockIds?: string[];
99
+ assets?: TDocumentAsset[];
100
+ };
101
+ /** Ephemeral/durable source map consumed by splitters to restore page and asset provenance. */
102
+ export type DocumentMarkdownSourceMap = {
103
+ schemaVersion: 1;
104
+ entries: DocumentMarkdownSourceMapEntry[];
105
+ };
106
+ /** Read model returned for one block in the paged analysis-preview API. */
107
+ export type KnowledgeDocumentAnalysisBlock = {
108
+ id: string;
109
+ order: number;
110
+ type: DocumentAnalysisBlockType;
111
+ providerType?: string;
112
+ providerSubType?: string;
113
+ markdown: string;
114
+ bounds?: DocumentAnalysisBounds;
115
+ polygon?: DocumentAnalysisPoint[];
116
+ assetId?: string;
117
+ };
118
+ /** Self-contained page record loaded independently for large documents. */
119
+ export type KnowledgeDocumentAnalysisPage = {
120
+ schemaVersion: 1;
121
+ page: number;
122
+ width: number;
123
+ height: number;
124
+ markdown: string;
125
+ blocks: KnowledgeDocumentAnalysisBlock[];
126
+ };
127
+ /** Capability response; unavailable snapshots expose a reason instead of throwing during page setup. */
128
+ export type KnowledgeDocumentAnalysisPreview = {
129
+ available: false;
130
+ reason: 'missing' | 'stale' | 'corrupt' | 'unsupported';
131
+ } | {
132
+ available: true;
133
+ schemaVersion: 1;
134
+ provider: string;
135
+ engine?: string;
136
+ pageCount: number;
137
+ pages: number[];
138
+ sourceType?: string;
139
+ sourceMimeType?: string;
140
+ views: Array<'markdown' | 'structure' | 'tables' | 'images' | 'json'>;
141
+ };
14
142
  export interface IDocChunkMetadata {
15
143
  chunkId: string;
16
144
  parentId?: string | null;
@@ -27,6 +155,21 @@ export interface IDocChunkMetadata {
27
155
  * Associated assets like images, videos, etc.
28
156
  */
29
157
  assets?: TDocumentAsset[];
158
+ /** Explicit content discriminator so generic preprocessing does not flatten Markdown syntax. */
159
+ contentFormat?: 'text' | 'markdown';
160
+ /** Global source page for a chunk contained entirely within one page. */
161
+ page?: number;
162
+ /** Inclusive global source-page interval when a chunk spans multiple pages. */
163
+ pageStart?: number;
164
+ pageEnd?: number;
165
+ /** Stable pre-merge layout identifiers contributing content to this chunk. */
166
+ sourceBlockIds?: string[];
167
+ /** Pre-split offset map; splitters must consume it instead of copying it to every final chunk. */
168
+ markdownSourceMap?: DocumentMarkdownSourceMap;
169
+ /** Durable source-map asset retained after the inline pre-split map is consumed. */
170
+ sourceMapAsset?: TDocumentAsset;
171
+ /** Original structured layout before text splitting. */
172
+ documentLayout?: DocumentLayoutMetadata;
30
173
  /**
31
174
  * Whether the chunk is represented as a vector in the vector store
32
175
  */
@@ -5,7 +5,7 @@ import { IKnowledgeDocumentPage } from './knowledge-doc-page.model';
5
5
  import { IKnowledgebaseTask } from './knowledgebase-task.model';
6
6
  import { IKnowledgebase, KBMetadataFieldDef } from './knowledgebase.model';
7
7
  import { TRagWebOptions } from './rag-web';
8
- import { IKnowledgeDocumentChunk } from './knowledge-doc-chunk.model';
8
+ import { DocumentAnalysisMetadata, IKnowledgeDocumentChunk } from './knowledge-doc-chunk.model';
9
9
  import { DocumentSourceProviderCategoryEnum } from './knowledge-pipeline';
10
10
  import { TCopilotModel } from './copilot-model.model';
11
11
  import { I18nObject } from '../types';
@@ -88,6 +88,52 @@ export declare enum KBDocumentStatusEnum {
88
88
  ERROR = "error"
89
89
  }
90
90
  export type KnowledgeDocumentIncrementalSyncMode = 'incremental' | 'full' | 'skipped';
91
+ /** `rechunk` reuses the saved pre-split transformer output and never invokes the converter. */
92
+ export type KnowledgeDocumentProcessingMode = 'full' | 'rechunk';
93
+ /** Converter identity included in fingerprints so credentials/config changes invalidate stale snapshots. */
94
+ export type KnowledgeDocumentTransformerIdentity = {
95
+ provider: string;
96
+ integrationId?: string | null;
97
+ config?: {
98
+ [key: string]: unknown;
99
+ } | null;
100
+ };
101
+ /** Integrity-checked reference to the pre-split converter output used by rechunk processing. */
102
+ export type KnowledgeDocumentTransformSnapshotRef = {
103
+ schemaVersion: 1;
104
+ filePath: string;
105
+ manifestPath: string;
106
+ sha256: string;
107
+ size: number;
108
+ itemCount: number;
109
+ chunkCount: number;
110
+ transformFingerprint: string;
111
+ sourceHash?: string | null;
112
+ transformer: KnowledgeDocumentTransformerIdentity;
113
+ createdAt: string;
114
+ };
115
+ /** Reference to the immutable, paged layout snapshot consumed by the analysis-preview API. */
116
+ export type KnowledgeDocumentAnalysisSnapshotRef = {
117
+ schemaVersion: 1;
118
+ manifestPath: string;
119
+ manifestSha256: string;
120
+ manifestSize: number;
121
+ transformFingerprint: string;
122
+ sourceHash?: string | null;
123
+ provider: string;
124
+ engine?: string;
125
+ pageCount: number;
126
+ createdAt: string;
127
+ };
128
+ /** Server-computed actions available for a document under its current source and converter fingerprint. */
129
+ export type KnowledgeDocumentReprocessCapabilities = {
130
+ full: true;
131
+ rechunk: {
132
+ available: boolean;
133
+ reason?: 'missing' | 'stale' | 'corrupt';
134
+ snapshot?: KnowledgeDocumentTransformSnapshotRef;
135
+ };
136
+ };
91
137
  export type KnowledgeDocumentLastIncrementalSync = {
92
138
  mode: KnowledgeDocumentIncrementalSyncMode;
93
139
  total: number;
@@ -194,8 +240,8 @@ export type TKnowledgeDocument = {
194
240
  integrationId?: string;
195
241
  integration?: IIntegration;
196
242
  /**
197
- * @deprecated use chunks instead
198
- */
243
+ * @deprecated use chunks instead
244
+ */
199
245
  pages?: IKnowledgeDocumentPage[];
200
246
  chunks?: IKnowledgeDocumentChunk[];
201
247
  tasks?: IKnowledgebaseTask[];
@@ -230,6 +276,9 @@ export interface StandardDocumentMetadata {
230
276
  lastIncrementalSync?: KnowledgeDocumentLastIncrementalSync;
231
277
  }
232
278
  export interface KnowledgeDocumentMetadata extends StandardDocumentMetadata {
279
+ transformSnapshot?: KnowledgeDocumentTransformSnapshotRef;
280
+ analysisSnapshot?: KnowledgeDocumentAnalysisSnapshotRef;
281
+ documentAnalysis?: DocumentAnalysisMetadata;
233
282
  [key: string]: any;
234
283
  }
235
284
  export interface IKnowledgeDocumentCreateInput extends IKnowledgeDocument, IBasePerTenantAndOrganizationEntityModel {
@@ -252,4 +301,4 @@ export declare const STANDARD_METADATA_FIELDS: {
252
301
  group: I18nObject;
253
302
  fields: KBMetadataFieldDef[];
254
303
  }[];
255
- export type StandardMetadataFieldKey = typeof STANDARD_METADATA_FIELDS[number]['fields'][number]['key'];
304
+ export type StandardMetadataFieldKey = (typeof STANDARD_METADATA_FIELDS)[number]['fields'][number]['key'];
@@ -0,0 +1,92 @@
1
+ export declare const KNOWLEDGE_FILTER_VERSION: 2;
2
+ export declare const KNOWLEDGE_FILTER_MAX_DEPTH = 3;
3
+ export declare const KNOWLEDGE_FILTER_MAX_CONDITIONS = 20;
4
+ export declare const KNOWLEDGE_FILTER_MAX_SET_VALUES = 100;
5
+ export declare const KNOWLEDGE_FILTER_MAX_STRING_LENGTH = 512;
6
+ export type KnowledgeFilterOperator = 'eq' | 'neq' | 'in' | 'notIn' | 'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'under' | 'gt' | 'gte' | 'lt' | 'lte' | 'between' | 'exists' | 'containsAny' | 'containsAll' | 'isEmpty' | 'jsonContains';
7
+ type KnowledgeFilterJSONPrimitive = null | string | number | boolean;
8
+ type KnowledgeFilterJSONObjectLevel1 = Record<string, KnowledgeFilterJSONPrimitive | KnowledgeFilterJSONPrimitive[]>;
9
+ /** A finite JSON shape keeps ORM DeepPartial types bounded while covering filter literals and JSON containment. */
10
+ export type KnowledgeFilterJSONValue = KnowledgeFilterJSONPrimitive | KnowledgeFilterJSONPrimitive[] | KnowledgeFilterJSONObjectLevel1 | KnowledgeFilterJSONObjectLevel1[] | Record<string, KnowledgeFilterJSONPrimitive | KnowledgeFilterJSONPrimitive[] | KnowledgeFilterJSONObjectLevel1 | KnowledgeFilterJSONObjectLevel1[]>;
11
+ export type KnowledgeFilterLiteralValue = {
12
+ kind: 'literal';
13
+ value: KnowledgeFilterJSONValue;
14
+ };
15
+ export type KnowledgeFilterVariableValue = {
16
+ kind: 'variable';
17
+ selector: string;
18
+ };
19
+ export type KnowledgeFilterValue = KnowledgeFilterLiteralValue | KnowledgeFilterVariableValue;
20
+ export type KnowledgeFilterCondition = {
21
+ kind: 'condition';
22
+ field: string;
23
+ operator: KnowledgeFilterOperator;
24
+ value?: KnowledgeFilterValue;
25
+ };
26
+ export type KnowledgeFilterGroupLevel1 = {
27
+ kind: 'group';
28
+ operator: 'and' | 'or';
29
+ children: KnowledgeFilterCondition[];
30
+ };
31
+ export type KnowledgeFilterGroupLevel2 = {
32
+ kind: 'group';
33
+ operator: 'and' | 'or';
34
+ children: Array<KnowledgeFilterCondition | KnowledgeFilterGroupLevel1>;
35
+ };
36
+ export type KnowledgeFilterGroupLevel3 = {
37
+ kind: 'group';
38
+ operator: 'and' | 'or';
39
+ children: Array<KnowledgeFilterCondition | KnowledgeFilterGroupLevel1 | KnowledgeFilterGroupLevel2>;
40
+ };
41
+ /** The fourth level is reserved for the server-owned root that merges validated sources. */
42
+ export type KnowledgeFilterGroupLevel4 = {
43
+ kind: 'group';
44
+ operator: 'and' | 'or';
45
+ children: Array<KnowledgeFilterCondition | KnowledgeFilterGroupLevel1 | KnowledgeFilterGroupLevel2 | KnowledgeFilterGroupLevel3>;
46
+ };
47
+ export type KnowledgeFilterGroup = KnowledgeFilterGroupLevel1 | KnowledgeFilterGroupLevel2 | KnowledgeFilterGroupLevel3 | KnowledgeFilterGroupLevel4;
48
+ export type KnowledgeFilterNode = KnowledgeFilterCondition | KnowledgeFilterGroup;
49
+ export type KnowledgeFilterSources = {
50
+ fixed?: KnowledgeFilterNode;
51
+ request?: KnowledgeFilterNode;
52
+ dynamic?: KnowledgeFilterNode;
53
+ };
54
+ export type KnowledgeFilterStatus = 'not_applied' | 'applied' | 'dynamic_fallback' | 'failed';
55
+ export type KnowledgeFilterErrorCode = 'invalid_filter' | 'unknown_field' | 'invalid_operator' | 'invalid_value' | 'missing_fixed_variable' | 'filter_too_complex' | 'graph_search_failed' | 'unsupported_backend' | 'unsupported_retrieval_mode';
56
+ export type KnowledgeFilterDiagnostics = {
57
+ filterVersion: typeof KNOWLEDGE_FILTER_VERSION;
58
+ fixedFilter?: KnowledgeFilterNode;
59
+ requestFilter?: KnowledgeFilterNode;
60
+ dynamicFilter?: KnowledgeFilterNode;
61
+ effectiveFilter?: KnowledgeFilterNode;
62
+ filterHash?: string;
63
+ filterStatus: KnowledgeFilterStatus;
64
+ fallbackReason?: 'invalid_dynamic_filter';
65
+ errorCode?: KnowledgeFilterErrorCode;
66
+ candidateDocumentCount?: number;
67
+ candidateChunkCount?: number;
68
+ hitCount: number;
69
+ vectorBackend?: string;
70
+ filterLatency?: number;
71
+ vectorLatency?: number;
72
+ vectorBranchHitCount?: number;
73
+ graphBranchHitCount?: number;
74
+ graphGlobalCandidateCount?: number;
75
+ graphCandidateScanLimit?: number;
76
+ graphCandidateScanRounds?: number;
77
+ graphCandidateTruncated?: boolean;
78
+ eligibleSeedEntityCount?: number;
79
+ eligibleRelationCount?: number;
80
+ eligibleMentionCount?: number;
81
+ graphCandidateChunkCount?: number;
82
+ graphSeedLatency?: number;
83
+ graphFilterLatency?: number;
84
+ graphExpansionLatency?: number;
85
+ graphChunkLatency?: number;
86
+ hybridGraphFallbackReason?: string;
87
+ retryableWithoutDynamic?: boolean;
88
+ errors?: string[];
89
+ };
90
+ export declare const KNOWLEDGE_SYSTEM_FILTER_FIELDS: readonly ["document.fileName", "document.folderPath", "document.fileExtension", "document.mimeType", "document.category", "document.sourceType", "document.createdAt", "document.updatedAt"];
91
+ export type KnowledgeSystemFilterField = (typeof KNOWLEDGE_SYSTEM_FILTER_FIELDS)[number];
92
+ export {};
@@ -1,10 +1,26 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model';
2
2
  import { IKnowledgebase } from './knowledgebase.model';
3
+ import { KnowledgeFilterDiagnostics, KnowledgeFilterNode, KnowledgeFilterStatus } from './knowledge-filter.model';
3
4
  export interface IKnowledgeRetrievalLog extends IBasePerTenantAndOrganizationEntityModel {
4
5
  query: string;
5
6
  source: string;
6
7
  hitCount: number;
7
8
  requestId: string;
9
+ filterVersion?: number;
10
+ fixedFilter?: KnowledgeFilterNode;
11
+ dynamicFilter?: KnowledgeFilterNode;
12
+ requestFilter?: KnowledgeFilterNode;
13
+ effectiveFilter?: KnowledgeFilterNode;
14
+ filterHash?: string;
15
+ filterStatus?: KnowledgeFilterStatus;
16
+ fallbackReason?: string;
17
+ errorCode?: string;
18
+ candidateDocumentCount?: number;
19
+ candidateChunkCount?: number;
20
+ vectorBackend?: string;
21
+ filterLatency?: number;
22
+ vectorLatency?: number;
23
+ diagnostics?: KnowledgeFilterDiagnostics;
8
24
  knowledgebaseId?: string;
9
25
  knowledgebase?: IKnowledgebase;
10
26
  }
@@ -1,6 +1,6 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model';
2
2
  import { IChatConversation } from './chat.model';
3
- import { IKnowledgeDocument } from './knowledge-doc.model';
3
+ import { IKnowledgeDocument, KnowledgeDocumentProcessingMode } from './knowledge-doc.model';
4
4
  import { IKnowledgebase } from './knowledgebase.model';
5
5
  import { IXpertAgentExecution } from './xpert-agent-execution.model';
6
6
  /**
@@ -22,6 +22,8 @@ export interface IKnowledgebaseTask extends IBasePerTenantAndOrganizationEntityM
22
22
  */
23
23
  context?: {
24
24
  documents?: Partial<IKnowledgeDocument>[];
25
+ /** Propagates full conversion vs. snapshot-only rechunking through the background task. */
26
+ processingMode?: KnowledgeDocumentProcessingMode;
25
27
  };
26
28
  /**
27
29
  * Many to Many of documents in task
@@ -186,6 +186,10 @@ export type KBMetadataFieldDef = {
186
186
  key: string;
187
187
  label?: I18nObject;
188
188
  type: MetadataFieldType;
189
+ /**
190
+ * Storage scope of the metadata value. Existing definitions are migrated to `document`.
191
+ */
192
+ scope?: 'document' | 'chunk';
189
193
  enumValues?: string[];
190
194
  description?: string;
191
195
  };
@@ -201,6 +205,8 @@ export declare const KnowledgeTask = "task_id";
201
205
  * Specify the data source to run
202
206
  */
203
207
  export declare const KNOWLEDGE_SOURCES_NAME = "sources";
208
+ /** Workflow-state key carrying the requested document processing resume point. */
209
+ export declare const KNOWLEDGE_PROCESSING_MODE_NAME = "processing_mode";
204
210
  export declare const KNOWLEDGE_DOCUMENTS_NAME = "documents";
205
211
  export declare const KNOWLEDGE_FOLDER_ID_NAME = "folder_id";
206
212
  export declare const KNOWLEDGE_STAGE_NAME = "stage";
@@ -1,7 +1,9 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel, IBasePerTenantEntityModel } from '../base-entity.model';
2
2
  import { IUser } from '../user.model';
3
+ import { AiModelTypeEnum } from '../agent';
3
4
  import { ModelAccessSourceEnum } from './model-access.model';
4
5
  import { ModelGatewayUsageChannelEnum } from './model-gateway.model';
6
+ import type { ModelUsageMetric, ModelUsageLedgerModality, ModelUsageLedgerOperation, ModelUsageOriginType, ModelUsagePriceRule, ModelUsagePricingStatus } from './model-usage.model';
5
7
  export declare enum MembershipPlanStatusEnum {
6
8
  Active = "active",
7
9
  Archived = "archived"
@@ -31,9 +33,8 @@ export declare enum MembershipPeriodStatusEnum {
31
33
  Completed = "completed",
32
34
  Cancelled = "cancelled"
33
35
  }
34
- export declare const DEFAULT_MEMBERSHIP_TOKENS_PER_POINT = 1000;
35
- export declare const MEMBERSHIP_TOKENS_PER_POINT_SETTING = "membershipTokensPerPoint";
36
- export declare const MEMBERSHIP_TOKENS_PER_POINT_OPTIONS: readonly [1000, 10000, 100000, 1000000];
36
+ export declare const DEFAULT_MEMBERSHIP_CNY_PER_POINT = 0.1;
37
+ export declare const MEMBERSHIP_CNY_PER_POINT_SETTING = "membershipCnyPerPoint";
37
38
  export declare enum MembershipLedgerSourceEnum {
38
39
  Assignment = "assignment",
39
40
  Grant = "grant",
@@ -43,7 +44,8 @@ export declare enum MembershipLedgerSourceEnum {
43
44
  Adjustment = "adjustment",
44
45
  StatusChange = "status_change",
45
46
  PersonalAdjustment = "personal_adjustment",
46
- PersonalUsage = "personal_usage"
47
+ PersonalUsage = "personal_usage",
48
+ ModelUsage = "model_usage"
47
49
  }
48
50
  export declare enum MembershipAdminUserStatusEnum {
49
51
  Active = "active",
@@ -62,6 +64,7 @@ export type TMembershipRateLimitPeriod = 'hour' | 'day' | 'week' | 'cycle';
62
64
  export interface IMembershipModelMultiplier {
63
65
  provider?: string | null;
64
66
  model?: string | null;
67
+ /** Applied to the CNY settlement amount before it is converted to membership points. */
65
68
  multiplier: number;
66
69
  }
67
70
  export interface IMembershipAllowedModel {
@@ -84,8 +87,9 @@ export interface IMembershipPlan extends IBasePerTenantAndOrganizationEntityMode
84
87
  isDefault?: boolean;
85
88
  period: MembershipPeriodEnum;
86
89
  includedPoints: number | null;
87
- tokensPerPoint: number;
90
+ /** @deprecated Sale pricing is owned by the Pro billing product. Retained temporarily for migration only. */
88
91
  priceAmount?: number | null;
92
+ /** @deprecated Sale pricing is owned by the Pro billing product. Retained temporarily for migration only. */
89
93
  priceCurrency?: string | null;
90
94
  allowedModels?: IMembershipAllowedModel[];
91
95
  modelMultipliers?: IMembershipModelMultiplier[];
@@ -100,7 +104,6 @@ export interface IMembershipPlanSnapshot {
100
104
  catalogSourcePlanId?: string | null;
101
105
  period: MembershipPeriodEnum;
102
106
  includedPoints: number | null;
103
- tokensPerPoint: number;
104
107
  allowedModels?: IMembershipAllowedModel[];
105
108
  modelMultipliers?: IMembershipModelMultiplier[];
106
109
  rateLimits?: IMembershipRateLimit[];
@@ -142,7 +145,7 @@ export interface IUserMembershipPeriod extends IBasePerTenantAndOrganizationEnti
142
145
  planSnapshot: IMembershipPlanSnapshot;
143
146
  }
144
147
  export interface IMembershipPointLedger extends IBasePerTenantEntityModel {
145
- userId: string;
148
+ userId?: string | null;
146
149
  user?: IUser;
147
150
  actorId?: string | null;
148
151
  actor?: IUser;
@@ -170,6 +173,36 @@ export interface IMembershipPointLedger extends IBasePerTenantEntityModel {
170
173
  gatewayApiKeyId?: string | null;
171
174
  chargedPoints?: number | null;
172
175
  excessPoints?: number | null;
176
+ requestId?: string | null;
177
+ revision?: number | null;
178
+ originType?: ModelUsageOriginType | null;
179
+ originId?: string | null;
180
+ originExecutionId?: string | null;
181
+ providerScopeId?: string | null;
182
+ modelType?: AiModelTypeEnum | null;
183
+ toolName?: string | null;
184
+ modality?: ModelUsageLedgerModality | null;
185
+ operation?: ModelUsageLedgerOperation | null;
186
+ unit?: ModelUsageMetric['unit'] | null;
187
+ authority?: ModelUsageMetric['authority'] | null;
188
+ quantity?: number | null;
189
+ promptTokens?: number | null;
190
+ completionTokens?: number | null;
191
+ totalTokens?: number | null;
192
+ recordedAt?: Date | string | null;
193
+ pricingStatus?: ModelUsagePricingStatus | null;
194
+ pricingRuleId?: string | null;
195
+ pricingRuleVersion?: string | null;
196
+ priceQuantity?: number | null;
197
+ unitSize?: number | null;
198
+ unitPrice?: number | null;
199
+ priceCurrency?: string | null;
200
+ priceAmount?: number | null;
201
+ pricingRule?: ModelUsagePriceRule | null;
202
+ chargedAt?: Date | string | null;
203
+ settlementCurrency?: string | null;
204
+ settlementAmount?: number | null;
205
+ exchangeRate?: number | null;
173
206
  }
174
207
  export interface IMembershipMe {
175
208
  membership: IUserMembership;
@@ -93,6 +93,11 @@ export interface IModelGatewayCall extends IBasePerTenantAndOrganizationEntityMo
93
93
  inputTokens: number;
94
94
  outputTokens: number;
95
95
  totalTokens: number;
96
+ priceAmount?: number | null;
97
+ priceCurrency?: string | null;
98
+ settlementAmount?: number | null;
99
+ settlementCurrency?: string | null;
100
+ exchangeRate?: number | null;
96
101
  chargedPoints: number;
97
102
  excessPoints: number;
98
103
  usageSource: ModelGatewayUsageSourceEnum;
@@ -0,0 +1,163 @@
1
+ import type { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model';
2
+ import type { AiModelTypeEnum } from '../agent';
3
+ export type ModelUsageModality = 'image' | 'video';
4
+ export type ModelUsageLedgerModality = 'text' | ModelUsageModality;
5
+ export type ImageGenerationOperation = 'text_to_image' | 'image_to_image' | 'multi_image_to_image';
6
+ export type VideoGenerationOperation = 'text_to_video' | 'image_to_video' | 'first_last_frame_to_video' | 'reference_to_video';
7
+ export type ModelUsageOperation = ImageGenerationOperation | VideoGenerationOperation;
8
+ export type ModelUsageLedgerOperation = AiModelTypeEnum | ModelUsageOperation;
9
+ export type ModelUsageOriginType = 'execution' | 'tool' | 'model';
10
+ export type ModelUsagePricingDimensions = {
11
+ resolution?: string;
12
+ audio?: boolean;
13
+ videoInput?: boolean;
14
+ durationSeconds?: number;
15
+ mode?: string;
16
+ };
17
+ export type ModelUsagePricingStatus = 'priced' | 'free' | 'unpriced';
18
+ export type ModelUsageChargeType = 'paid' | 'free';
19
+ export type ModelUsageTokenType = 'prompt' | 'completion' | 'total';
20
+ export type ModelUsagePriceRule = {
21
+ id: string;
22
+ version: string;
23
+ effective_from: string;
24
+ effective_to?: string;
25
+ unit: ModelUsageMetric['unit'];
26
+ token_type?: ModelUsageTokenType;
27
+ unit_size: number;
28
+ unit_price?: number;
29
+ currency?: string;
30
+ charge_type: ModelUsageChargeType;
31
+ operations?: ModelUsageOperation[];
32
+ dimensions?: Partial<Omit<ModelUsagePricingDimensions, 'durationSeconds'>>;
33
+ source_url?: string;
34
+ };
35
+ export type ModelUsagePricingConfig = {
36
+ type: 'usage';
37
+ rules: ModelUsagePriceRule[];
38
+ };
39
+ export type ModelUsagePricingContext = {
40
+ model: string;
41
+ operation: ModelUsageOperation;
42
+ modality: ModelUsageModality;
43
+ pricingDimensions?: ModelUsagePricingDimensions;
44
+ startedAt?: Date | string;
45
+ };
46
+ export type ModelUsagePricingSnapshot = {
47
+ capturedAt: string;
48
+ rules: ModelUsagePriceRule[];
49
+ };
50
+ export type ModelUsageMetric = {
51
+ unit: 'token';
52
+ promptTokens?: number;
53
+ completionTokens?: number;
54
+ totalTokens?: number;
55
+ authority: 'provider';
56
+ } | {
57
+ unit: 'generation';
58
+ quantity: number;
59
+ authority: 'provider' | 'contract';
60
+ } | {
61
+ unit: 'second';
62
+ quantity: number;
63
+ authority: 'provider' | 'request';
64
+ };
65
+ /** Final, authoritative usage emitted after a model request has completed. */
66
+ export type ModelUsageReport = {
67
+ requestId: string;
68
+ model?: string;
69
+ modelType: AiModelTypeEnum;
70
+ toolName?: string;
71
+ operation: ModelUsageOperation;
72
+ modality: ModelUsageModality;
73
+ pricingDimensions?: ModelUsagePricingDimensions;
74
+ pricingSnapshot?: ModelUsagePricingSnapshot;
75
+ metrics: ModelUsageMetric[];
76
+ recordedAt?: Date | string;
77
+ };
78
+ export type ModelUsageReportResult = {
79
+ requestId: string;
80
+ recorded: boolean;
81
+ ledgerIds: string[];
82
+ };
83
+ export interface IModelUsageLedger extends IBasePerTenantAndOrganizationEntityModel {
84
+ requestId: string;
85
+ revision: number;
86
+ userId?: string | null;
87
+ userName?: string | null;
88
+ originType: ModelUsageOriginType;
89
+ originId: string;
90
+ originExecutionId?: string | null;
91
+ copilotId: string;
92
+ providerScopeId: string;
93
+ provider: string;
94
+ model?: string | null;
95
+ modelType: AiModelTypeEnum;
96
+ toolName?: string | null;
97
+ modality: ModelUsageLedgerModality;
98
+ operation: ModelUsageLedgerOperation;
99
+ unit: ModelUsageMetric['unit'];
100
+ authority: ModelUsageMetric['authority'];
101
+ quantity?: number | null;
102
+ promptTokens?: number | null;
103
+ completionTokens?: number | null;
104
+ totalTokens?: number | null;
105
+ recordedAt: Date;
106
+ charge?: IModelChargeLedger | null;
107
+ }
108
+ export interface IModelUsageDetails {
109
+ requestId: string;
110
+ providerScopeId: string;
111
+ originExecutionId?: string | null;
112
+ provider: string;
113
+ model?: string | null;
114
+ modelType: AiModelTypeEnum;
115
+ toolName?: string | null;
116
+ modality: ModelUsageModality;
117
+ operation: ModelUsageOperation;
118
+ metrics: ModelUsageMetric[];
119
+ recordedAt: Date;
120
+ }
121
+ export interface IModelChargeLedger extends IBasePerTenantAndOrganizationEntityModel {
122
+ usageLedgerId: string;
123
+ pricingStatus: ModelUsagePricingStatus;
124
+ pricingRuleId?: string | null;
125
+ pricingRuleVersion?: string | null;
126
+ unit: ModelUsageMetric['unit'];
127
+ quantity: number;
128
+ unitSize?: number | null;
129
+ unitPrice?: number | null;
130
+ currency?: string | null;
131
+ amount?: number | null;
132
+ pricingRule?: ModelUsagePriceRule | null;
133
+ chargedAt: Date;
134
+ settlementCurrency?: string | null;
135
+ settlementAmount?: number | null;
136
+ exchangeRate?: number | null;
137
+ }
138
+ export type ModelUsageLedgerQuery = {
139
+ start?: string;
140
+ end?: string;
141
+ provider?: string;
142
+ model?: string;
143
+ userId?: string;
144
+ organizationId?: string;
145
+ unit?: ModelUsageMetric['unit'];
146
+ modality?: ModelUsageLedgerModality;
147
+ currency?: string;
148
+ pricingStatus?: ModelUsagePricingStatus;
149
+ };
150
+ export type ModelUsageLedgerTotals = {
151
+ modality: ModelUsageLedgerModality;
152
+ unit: ModelUsageMetric['unit'];
153
+ currency?: string | null;
154
+ pricingStatus: ModelUsagePricingStatus;
155
+ quantity: number;
156
+ promptTokens: number;
157
+ completionTokens: number;
158
+ totalTokens: number;
159
+ amount?: number | null;
160
+ settlementCurrency?: string | null;
161
+ settlementAmount?: number | null;
162
+ records: number;
163
+ };