@metad/contracts 3.8.0 → 3.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metad/contracts",
3
- "version": "3.8.0",
3
+ "version": "3.8.3",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,6 +3,23 @@ export type TTokenUsage = {
3
3
  completionTokens: number;
4
4
  totalTokens: number;
5
5
  };
6
+ export type TThreadContextUsageMetrics = {
7
+ contextTokens: number;
8
+ inputTokens: number;
9
+ outputTokens: number;
10
+ totalTokens: number;
11
+ embedTokens: number;
12
+ totalPrice: number;
13
+ currency: string | null;
14
+ };
15
+ export type TThreadContextUsageEvent = {
16
+ type: 'thread_context_usage';
17
+ threadId: string;
18
+ runId: string | null;
19
+ agentKey: string;
20
+ updatedAt: string;
21
+ usage: TThreadContextUsageMetrics;
22
+ };
6
23
  export interface IModelUsage {
7
24
  totalTokens: number;
8
25
  totalPrice: number;
@@ -2,7 +2,7 @@ import { MessageType } from '@langchain/core/messages';
2
2
  import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model';
3
3
  import { IChatConversation } from './chat.model';
4
4
  import { LongTermMemoryTypeEnum } from './xpert.model';
5
- import { XpertAgentExecutionStatusEnum } from './xpert-agent-execution.model';
5
+ import { IXpertAgentExecution, XpertAgentExecutionStatusEnum } from './xpert-agent-execution.model';
6
6
  import { JSONValue } from '../core.model';
7
7
  import { IStorageFile } from '../storage-file.model';
8
8
  import { TChatMessageStep, TMessageContent, TMessageContentReasoning } from '@xpert-ai/chatkit-types';
@@ -41,6 +41,7 @@ export interface IChatMessage extends IBasePerTenantAndOrganizationEntityModel,
41
41
  conversation?: IChatConversation;
42
42
  conversationId?: string | null;
43
43
  executionId?: string;
44
+ execution?: IXpertAgentExecution;
44
45
  }
45
46
  /**
46
47
  * @deprecated
@@ -52,7 +53,7 @@ export type ChatMessageStatusEnum = XpertAgentExecutionStatusEnum | 'thinking' |
52
53
  * BaseMessage or AIMessage in Langchain.js
53
54
  */
54
55
  export interface CopilotBaseMessage {
55
- id: string;
56
+ id?: string;
56
57
  createdAt?: Date;
57
58
  role: CopilotMessageType;
58
59
  /**
package/src/ai/index.d.ts CHANGED
@@ -42,3 +42,4 @@ export * from './knowledge-doc-chunk.model';
42
42
  export * from './skill.model';
43
43
  export * from './middleware.model';
44
44
  export * from './sandbox';
45
+ export * from './message-content.utils';
@@ -0,0 +1,52 @@
1
+ import { TMessageContent, TMessageContentComplex } from '@xpert-ai/chatkit-types';
2
+ import { CopilotChatMessage } from './chat-message.model';
3
+ export type TMessageJoinHint = 'none' | 'space' | 'line' | 'paragraph';
4
+ export type TMessageAppendContext = {
5
+ source?: string;
6
+ streamId?: string;
7
+ joinHint?: TMessageJoinHint;
8
+ };
9
+ export type TAppendMessageContentOptions = TMessageAppendContext & {
10
+ previous?: TMessageAppendContext | null;
11
+ };
12
+ export type TResolveMessageAppendContextOptions = {
13
+ previous?: TMessageAppendContext | null;
14
+ incoming: string | TMessageContentComplex;
15
+ fallbackSource?: string;
16
+ fallbackStreamId?: string;
17
+ };
18
+ export type TResolvedMessageAppendContext = {
19
+ appendContext: TMessageAppendContext;
20
+ messageContext: TMessageAppendContext;
21
+ };
22
+ export type TMessageAppendContextTracker = {
23
+ resolve: (options: Omit<TResolveMessageAppendContextOptions, 'previous'>) => TResolvedMessageAppendContext;
24
+ reset: () => void;
25
+ current: () => TMessageAppendContext | null;
26
+ };
27
+ export declare function inferMessageAppendContext(content: string | TMessageContentComplex, fallbackSource?: string): TMessageAppendContext;
28
+ export declare function resolveMessageAppendContext(options: TResolveMessageAppendContextOptions): TResolvedMessageAppendContext;
29
+ /**
30
+ * Stateful helper for streaming append.
31
+ *
32
+ * It keeps the previous append context and resolves the current one, so callers
33
+ * can avoid passing `previous` manually for every chunk and still get stable
34
+ * join behavior (for example, same source + same stream -> `joinHint: 'none'`).
35
+ *
36
+ * Call `reset()` at turn/session boundaries to prevent cross-turn contamination.
37
+ */
38
+ export declare function createMessageAppendContextTracker(initial?: TMessageAppendContext | null): TMessageAppendContextTracker;
39
+ /**
40
+ * Append one incoming chunk into a chat message in place.
41
+ *
42
+ * Behavior:
43
+ * - Keeps `aiMessage` object reference stable (caller may hold this object).
44
+ * - Updates message properties with new references (`content`/`reasoning` arrays)
45
+ * so UI change detection that relies on reference changes can react reliably.
46
+ * - Applies context-aware merge rules for text/reasoning/component chunks.
47
+ * - `previous` must be supplied by caller when same-stream join inference is needed.
48
+ */
49
+ export declare function appendMessageContent(aiMessage: CopilotChatMessage, incoming: string | TMessageContentComplex, context?: TAppendMessageContentOptions): void;
50
+ export declare function appendMessagePlainText(accumulator: string, incoming: string | TMessageContentComplex, context?: TMessageAppendContext): string;
51
+ export declare function stringifyMessageContent(content: TMessageContent | TMessageContentComplex): string;
52
+ export declare function filterMessageText(content: TMessageContent | TMessageContentComplex): string;
@@ -1,7 +1,8 @@
1
1
  export declare enum MCPServerType {
2
2
  SSE = "sse",
3
3
  STDIO = "stdio",
4
- CODE = "code"
4
+ CODE = "code",
5
+ HTTP = "http"
5
6
  }
6
7
  /**
7
8
  * Configuration for stdio transport connection
@@ -23,6 +24,19 @@ export interface SSEConnection {
23
24
  headers?: Record<string, string>;
24
25
  useNodeEventSource?: boolean;
25
26
  }
27
+ /**
28
+ * Configuration for Streamable HTTP transport connection
29
+ */
30
+ export interface HttpConnection {
31
+ transport: "http";
32
+ url: string;
33
+ headers?: Record<string, string>;
34
+ /**
35
+ * Whether to automatically fallback to SSE if Streamable HTTP is not available.
36
+ * Defaults to true.
37
+ */
38
+ automaticSSEFallback?: boolean;
39
+ }
26
40
  export type TMCPServerReconnect = {
27
41
  /**
28
42
  * Whether to automatically restart the process if it exits
@@ -51,6 +65,11 @@ export type TMCPServer = {
51
65
  url?: string;
52
66
  headers?: Record<string, string>;
53
67
  useNodeEventSource?: boolean;
68
+ /**
69
+ * Whether to automatically fallback to SSE if Streamable HTTP is not available.
70
+ * Defaults to true. Only applicable for HTTP transport.
71
+ */
72
+ automaticSSEFallback?: boolean;
54
73
  /**
55
74
  * Default timeout in milliseconds for tool execution. Must be greater than 0.
56
75
  * If not specified, tools will use their own configured timeout values.
@@ -1,5 +1,4 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel } from '../base-entity.model';
2
- import { FileStorageProviderEnum } from '../file-provider';
3
2
  export interface IScreenshot extends IBasePerTenantAndOrganizationEntityModel {
4
3
  file: string;
5
4
  url?: string;
@@ -11,7 +10,7 @@ export interface IScreenshot extends IBasePerTenantAndOrganizationEntityModel {
11
10
  thumbUrl?: string;
12
11
  recordedAt?: Date;
13
12
  size?: number;
14
- storageProvider?: FileStorageProviderEnum;
13
+ storageProvider?: string;
15
14
  }
16
15
  export interface IUpdateScreenshotInput extends ICreateScreenshotInput {
17
16
  id: string;
@@ -0,0 +1,77 @@
1
+ import { IStorageFile } from './storage-file.model';
2
+ export type FileAssetStatus = 'success' | 'partial_success' | 'failed';
3
+ export type FileAssetDestinationKind = 'storage' | 'volume' | 'sandbox';
4
+ export type FileAssetSourceKind = 'multipart' | 'storage_file' | 'local_file';
5
+ export type FileUploadVolumeCatalog = 'projects' | 'users' | 'knowledges' | 'skills';
6
+ export type FileUploadSandboxMode = 'mounted_workspace' | 'backend_upload';
7
+ export interface IFileAssetSource {
8
+ kind: FileAssetSourceKind;
9
+ name?: string;
10
+ originalName?: string;
11
+ mimeType?: string;
12
+ size?: number;
13
+ storageFileId?: string;
14
+ filePath?: string;
15
+ metadata?: Record<string, any>;
16
+ }
17
+ export interface IFileAssetDestination {
18
+ kind: FileAssetDestinationKind;
19
+ status: 'success' | 'failed';
20
+ path?: string;
21
+ url?: string;
22
+ referenceId?: string;
23
+ metadata?: Record<string, any>;
24
+ error?: string;
25
+ }
26
+ export interface IFileAsset {
27
+ name?: string;
28
+ originalName?: string;
29
+ mimeType?: string;
30
+ size?: number;
31
+ status: FileAssetStatus;
32
+ metadata?: Record<string, any>;
33
+ source?: IFileAssetSource;
34
+ destinations: IFileAssetDestination[];
35
+ }
36
+ export interface IUploadFileStorageTarget {
37
+ kind: 'storage';
38
+ strategy?: string;
39
+ provider?: string;
40
+ providerOptions?: Record<string, any>;
41
+ directory?: string;
42
+ fileName?: string;
43
+ prefix?: string;
44
+ metadata?: Record<string, any>;
45
+ }
46
+ export interface IUploadFileVolumeTarget {
47
+ kind: 'volume';
48
+ strategy?: string;
49
+ catalog: FileUploadVolumeCatalog;
50
+ projectId?: string;
51
+ knowledgeId?: string;
52
+ userId?: string;
53
+ tenantId?: string;
54
+ folder?: string;
55
+ fileName?: string;
56
+ metadata?: Record<string, any>;
57
+ }
58
+ export interface IUploadFileSandboxTarget {
59
+ kind: 'sandbox';
60
+ strategy?: string;
61
+ mode: FileUploadSandboxMode;
62
+ workspacePath?: string;
63
+ workspaceUrl?: string;
64
+ workspaceId?: string;
65
+ sandboxUrl?: string;
66
+ folder?: string;
67
+ fileName?: string;
68
+ metadata?: Record<string, any>;
69
+ }
70
+ export type IUploadFileTarget = IUploadFileStorageTarget | IUploadFileVolumeTarget | IUploadFileSandboxTarget;
71
+ export type TStorageFileAssetDestination = IFileAssetDestination & {
72
+ kind: 'storage';
73
+ referenceId?: IStorageFile['id'];
74
+ metadata?: Record<string, any> & {
75
+ storageFile?: IStorageFile;
76
+ };
77
+ };
@@ -1,6 +1,6 @@
1
1
  export interface FileStorageOption {
2
2
  dest: string | CallableFunction;
3
- provider?: FileStorageProviderEnum;
3
+ provider?: string;
4
4
  prefix?: string;
5
5
  filename?: string | CallableFunction;
6
6
  }
@@ -9,10 +9,7 @@ export interface FileSystem {
9
9
  baseUrl?: string;
10
10
  }
11
11
  export declare enum FileStorageProviderEnum {
12
- LOCAL = "LOCAL",
13
- S3 = "S3",
14
- WASABI = "WASABI",
15
- OSS = "OSS"
12
+ LOCAL = "LOCAL"
16
13
  }
17
14
  export interface UploadedFile {
18
15
  fieldname: string;
@@ -30,4 +27,5 @@ export interface S3FileStorageProviderConfig {
30
27
  aws_secret_access_key?: string;
31
28
  aws_default_region?: string;
32
29
  aws_bucket?: string;
30
+ aws_endpoint?: string;
33
31
  }
package/src/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from './employee.model';
9
9
  export * from './entity-with-members.model';
10
10
  export * from './feature.model';
11
11
  export * from './file-provider';
12
+ export * from './file-asset.model';
12
13
  export * from './http-status.enum';
13
14
  export * from './import-export.model';
14
15
  export * from './language.model';
package/src/plugin.d.ts CHANGED
@@ -1,9 +1,24 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel } from './base-entity.model';
2
+ import { JsonSchemaObjectType } from './ai/types';
2
3
  import { IconDefinition } from './types';
3
4
  export type PluginName = string;
5
+ export declare const PLUGIN_LEVEL: {
6
+ readonly SYSTEM: "system";
7
+ readonly ORGANIZATION: "organization";
8
+ };
9
+ /**
10
+ * Classifies plugin scope and governance.
11
+ * - `system`: built-in/platform-managed plugin that users cannot install/uninstall from org APIs.
12
+ * - `organization`: tenant/org-managed plugin that can be installed and removed per organization.
13
+ */
14
+ export type PluginLevel = (typeof PLUGIN_LEVEL)[keyof typeof PLUGIN_LEVEL];
4
15
  export interface PluginMeta {
5
16
  name: PluginName;
6
17
  version: string;
18
+ /**
19
+ * Declares the plugin's operational level used for visibility and install/uninstall guardrails.
20
+ */
21
+ level?: PluginLevel;
7
22
  icon?: IconDefinition;
8
23
  category: 'set' | 'doc-source' | 'agent' | 'tools' | 'model' | 'vlm' | 'vector-store' | 'integration' | 'datasource' | 'database' | 'middleware';
9
24
  displayName: string;
@@ -16,6 +31,21 @@ export interface IPlugin extends IBasePerTenantAndOrganizationEntityModel {
16
31
  pluginName: string;
17
32
  packageName: string;
18
33
  version?: string;
19
- source?: "marketplace" | "local" | "git" | "url" | "npm" | "code";
34
+ source?: 'marketplace' | 'local' | 'git' | 'url' | 'npm' | 'code' | 'env';
35
+ level?: PluginLevel;
20
36
  config: Record<string, any>;
21
37
  }
38
+ export interface IPluginDescriptor {
39
+ organizationId?: string;
40
+ name: PluginName;
41
+ meta: PluginMeta;
42
+ isGlobal: boolean;
43
+ level: PluginLevel;
44
+ canConfigure?: boolean;
45
+ configSchema?: JsonSchemaObjectType;
46
+ }
47
+ export interface IPluginConfiguration<TConfig extends Record<string, any> = Record<string, any>> {
48
+ pluginName: PluginName;
49
+ config: TConfig;
50
+ configSchema?: JsonSchemaObjectType;
51
+ }
@@ -1,5 +1,4 @@
1
1
  import { IBasePerTenantAndOrganizationEntityModel } from './base-entity.model';
2
- import { FileStorageProviderEnum } from './file-provider';
3
2
  import { _TFile } from './types';
4
3
  export type TFile = _TFile & {
5
4
  fileType?: string;
@@ -20,7 +19,7 @@ export interface IStorageFile extends IBasePerTenantAndOrganizationEntityModel {
20
19
  size?: number;
21
20
  mimetype?: string;
22
21
  recordedAt?: Date;
23
- storageProvider?: FileStorageProviderEnum;
22
+ storageProvider?: string;
24
23
  }
25
24
  export interface ICreateStorageFileInput extends IBasePerTenantAndOrganizationEntityModel {
26
25
  activityTimestamp: string;
@@ -1,6 +1,6 @@
1
1
  import { IImportRecord } from './import-export.model';
2
2
  import { IFeatureOrganization } from './feature.model';
3
- import { FileStorageProviderEnum, S3FileStorageProviderConfig } from './file-provider';
3
+ import { S3FileStorageProviderConfig } from './file-provider';
4
4
  import { IOrganization, IOrganizationCreateInput } from './organization.model';
5
5
  import { IRolePermission } from './role-permission.model';
6
6
  import { IUserCreateInput } from './user.model';
@@ -28,7 +28,7 @@ export interface ISetting {
28
28
  value: string;
29
29
  }
30
30
  export interface ITenantSetting extends S3FileStorageProviderConfig {
31
- fileStorageProvider?: FileStorageProviderEnum;
31
+ fileStorageProvider?: string;
32
32
  tenant_title?: string;
33
33
  tenant_title_en?: string;
34
34
  tenant_enable_feishu?: boolean;