@xpert-ai/plugin-sdk 3.16.1 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/_extends.cjs.js +14 -0
- package/_extends.esm.js +12 -0
- package/collaboration-client.cjs.js +392 -8
- package/collaboration-client.esm.js +389 -1
- package/index.cjs.js +500 -285
- package/index.esm.js +444 -247
- package/model-provider-http-client.cjs.default.js +1 -0
- package/model-provider-http-client.cjs.js +118 -0
- package/model-provider-http-client.cjs.mjs +2 -0
- package/model-provider-http-client.d.ts +1 -0
- package/model-provider-http-client.esm.js +115 -0
- package/model-provider-toolset.cjs.default.js +1 -0
- package/model-provider-toolset.cjs.js +12 -0
- package/model-provider-toolset.cjs.mjs +2 -0
- package/model-provider-toolset.d.ts +1 -0
- package/model-provider-toolset.esm.js +6 -0
- package/model-provider.cjs.js +348 -0
- package/model-provider.esm.js +328 -0
- package/package.json +14 -2
- package/src/index.d.ts +1 -0
- package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +3 -0
- package/src/lib/agent/middleware/index.d.ts +1 -0
- package/src/lib/agent/middleware/model-output-validation-error.d.ts +27 -0
- package/src/lib/agent/middleware/runtime.d.ts +43 -4
- package/src/lib/ai-model/abstract-provider.d.ts +2 -2
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -3
- package/src/lib/ai-model/ai-model.d.ts +4 -1
- package/src/lib/ai-model/index.d.ts +2 -0
- package/src/lib/ai-model/llm.d.ts +49 -3
- package/src/lib/ai-model/managed-aigc-job.d.ts +37 -0
- package/src/lib/ai-model/model-provider-http-client.d.ts +51 -0
- package/src/lib/ai-model/pricing.d.ts +13 -1
- package/src/lib/ai-model/types/aigc.d.ts +39 -0
- package/src/lib/ai-model/types/index.d.ts +1 -0
- package/src/lib/ai-model/types/model.d.ts +10 -4
- package/src/lib/core/runtime-capability.d.ts +2 -0
- package/src/lib/evolution/index.d.ts +4 -0
- package/src/lib/evolution/provider.decorator.d.ts +2 -0
- package/src/lib/evolution/provider.registry.d.ts +7 -0
- package/src/lib/evolution/runtime-capability.d.ts +3 -0
- package/src/lib/managed-queue/index.d.ts +3 -1
- package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +59 -1
- package/src/lib/runtime/capabilities/knowledgebase.d.ts +95 -3
- package/src/lib/runtime/capabilities/workspace-files.d.ts +5 -0
- package/src/lib/toolset/builtin.d.ts +28 -0
- package/src/lib/toolset/index.d.ts +1 -0
- package/src/lib/toolset/model-provider.d.ts +31 -0
- package/src/lib/vectorstore/strategy.interface.d.ts +3 -0
- package/src/model-provider-http-client.d.ts +1 -0
- package/src/model-provider-toolset.d.ts +1 -0
- package/collaboration-client.cjs2.js +0 -406
- package/collaboration-client.esm2.js +0 -398
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ModelUsageModality, type ModelUsageOperation, type ModelUsagePricingDimensions, type ModelUsagePricingSnapshot } from '@xpert-ai/contracts';
|
|
2
|
+
import type { AgentMiddlewareModelProviderConnection } from '../agent/middleware/runtime';
|
|
3
|
+
import type { ManagedQueueJob } from '../managed-queue';
|
|
4
|
+
import type { AIGCModelObservation, AsyncAIGCModelClient } from './types/aigc';
|
|
5
|
+
export type AsyncAIGCManagedJobPhase = 'queued' | 'submitted' | 'processing' | 'succeeded' | 'failed';
|
|
6
|
+
/** Durable provider checkpoint stored inside the Managed Queue payload. */
|
|
7
|
+
export type AsyncAIGCManagedJobPayload<TInput, TResult> = {
|
|
8
|
+
requestId: string;
|
|
9
|
+
model: string;
|
|
10
|
+
toolName: string;
|
|
11
|
+
modality: ModelUsageModality;
|
|
12
|
+
operation: ModelUsageOperation;
|
|
13
|
+
pricingDimensions?: ModelUsagePricingDimensions;
|
|
14
|
+
input: TInput;
|
|
15
|
+
phase: AsyncAIGCManagedJobPhase;
|
|
16
|
+
startedAt: string;
|
|
17
|
+
providerRequestId?: string;
|
|
18
|
+
providerState?: AIGCModelObservation['state'];
|
|
19
|
+
pricingSnapshot?: ModelUsagePricingSnapshot;
|
|
20
|
+
usageReported?: boolean;
|
|
21
|
+
result?: TResult;
|
|
22
|
+
errorCode?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ProcessAsyncAIGCManagedJobOptions<TInput, TData, TResult> = {
|
|
25
|
+
client: AsyncAIGCModelClient<TInput, TData>;
|
|
26
|
+
provider: AgentMiddlewareModelProviderConnection;
|
|
27
|
+
pollIntervalMs?: number;
|
|
28
|
+
sleep?: (milliseconds: number) => Promise<void>;
|
|
29
|
+
finalize(data: TData): Promise<TResult>;
|
|
30
|
+
failureMessage?(data: TData, observation: AIGCModelObservation): string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Runs one asynchronous provider request inside a Managed Queue job.
|
|
34
|
+
* Provider acceptance, terminal usage reporting, and result delivery are checkpointed so a queue retry resumes
|
|
35
|
+
* from the last durable provider request instead of intentionally submitting a second request.
|
|
36
|
+
*/
|
|
37
|
+
export declare function processAsyncAIGCManagedJob<TInput, TData, TResult>(job: ManagedQueueJob<AsyncAIGCManagedJobPayload<TInput, TResult>>, options: ProcessAsyncAIGCManagedJobOptions<TInput, TData, TResult>): Promise<TResult>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type ModelProviderHttpClientOptions = {
|
|
2
|
+
provider: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
defaultHeaders?: Readonly<Record<string, string>>;
|
|
5
|
+
fetchImpl?: typeof fetch;
|
|
6
|
+
requestTimeoutMs?: number;
|
|
7
|
+
};
|
|
8
|
+
export type ModelProviderBufferOptions = {
|
|
9
|
+
maxBytes?: number;
|
|
10
|
+
maxBytesError?: string;
|
|
11
|
+
defaultMimeType?: string;
|
|
12
|
+
};
|
|
13
|
+
export type ModelProviderHttpResponse = {
|
|
14
|
+
ok: boolean;
|
|
15
|
+
status: number;
|
|
16
|
+
statusText: string;
|
|
17
|
+
headers: {
|
|
18
|
+
get(name: string): string | null;
|
|
19
|
+
};
|
|
20
|
+
text(): Promise<string>;
|
|
21
|
+
json(): Promise<unknown>;
|
|
22
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
23
|
+
};
|
|
24
|
+
export declare class ModelProviderHttpError extends Error {
|
|
25
|
+
readonly status: number;
|
|
26
|
+
constructor(message: string, status: number);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Shared HTTP transport for model Provider adapters.
|
|
30
|
+
*
|
|
31
|
+
* Provider-specific authentication headers are supplied at construction time;
|
|
32
|
+
* response parsing, task semantics, and download URL policy stay in each adapter.
|
|
33
|
+
*/
|
|
34
|
+
export declare abstract class ModelProviderHttpClient {
|
|
35
|
+
protected readonly baseUrl: string;
|
|
36
|
+
private readonly provider;
|
|
37
|
+
private readonly defaultHeaders;
|
|
38
|
+
private readonly fetchImpl;
|
|
39
|
+
private readonly requestTimeoutMs?;
|
|
40
|
+
protected constructor(options: ModelProviderHttpClientOptions);
|
|
41
|
+
protected requestJson<T>(pathOrUrl: string, init: RequestInit, parse: (value: unknown) => T): Promise<T>;
|
|
42
|
+
protected fetchResponse(input: string | URL, init?: RequestInit, timeoutMs?: number): Promise<ModelProviderHttpResponse>;
|
|
43
|
+
protected readBufferResponse(response: ModelProviderHttpResponse, options?: ModelProviderBufferOptions): Promise<{
|
|
44
|
+
buffer: Buffer;
|
|
45
|
+
mimeType?: string;
|
|
46
|
+
}>;
|
|
47
|
+
protected createHttpError(response: ModelProviderHttpResponse): Promise<Error>;
|
|
48
|
+
protected createTimeoutError(timeoutMs: number): Error;
|
|
49
|
+
private resolveRequestUrl;
|
|
50
|
+
private mergeHeaders;
|
|
51
|
+
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import { PriceConfig, PriceInfo, PriceType } from '@xpert-ai/contracts';
|
|
1
|
+
import { type ModelUsagePricingSnapshot, type ModelUsageMetric, type ModelUsagePriceRule, type ModelUsagePricingConfig, type ModelUsagePricingContext, type ModelUsagePricingStatus, PriceConfig, PriceInfo, PriceType } from '@xpert-ai/contracts';
|
|
2
2
|
export declare function calculateModelPrice(pricing: PriceConfig, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
|
|
3
|
+
export type ModelUsageChargeCalculation = {
|
|
4
|
+
pricingStatus: ModelUsagePricingStatus;
|
|
5
|
+
pricingRule?: ModelUsagePriceRule;
|
|
6
|
+
quantity: number;
|
|
7
|
+
unitSize?: number;
|
|
8
|
+
unitPrice?: number;
|
|
9
|
+
currency?: string;
|
|
10
|
+
amount?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function resolveModelUsagePricingSnapshot(pricing: PriceConfig | ModelUsagePricingConfig | undefined, context: ModelUsagePricingContext): ModelUsagePricingSnapshot;
|
|
13
|
+
export declare function calculateModelUsageCharge(snapshot: ModelUsagePricingSnapshot | null | undefined, metric: ModelUsageMetric): ModelUsageChargeCalculation;
|
|
14
|
+
export declare function isModelUsagePricingConfig(pricing: PriceConfig | ModelUsagePricingConfig | undefined): pricing is ModelUsagePricingConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ICopilotModel, ModelUsageMetric, ModelUsageOperation, ModelUsagePricingDimensions } from '@xpert-ai/contracts';
|
|
2
|
+
import { AIModel } from '../ai-model';
|
|
3
|
+
import type { TChatModelOptions } from './model';
|
|
4
|
+
export type AIGCModelState = 'submitted' | 'processing' | 'succeeded' | 'failed' | 'cancelled';
|
|
5
|
+
export type AIGCModelObservation = {
|
|
6
|
+
state: AIGCModelState;
|
|
7
|
+
metrics?: ModelUsageMetric[];
|
|
8
|
+
errorCode?: string;
|
|
9
|
+
};
|
|
10
|
+
export interface AIGCModelClient<TInput = unknown, TOutput = unknown> {
|
|
11
|
+
invoke(input: TInput): Promise<AIGCModelResult<TOutput>>;
|
|
12
|
+
}
|
|
13
|
+
export type AIGCModelResult<TData> = {
|
|
14
|
+
data: TData;
|
|
15
|
+
observation: AIGCModelObservation;
|
|
16
|
+
};
|
|
17
|
+
export type AsyncAIGCModelSubmission<TData> = {
|
|
18
|
+
providerRequestId: string;
|
|
19
|
+
data: TData;
|
|
20
|
+
};
|
|
21
|
+
export type AsyncAIGCModelQueryContext = {
|
|
22
|
+
operation?: ModelUsageOperation;
|
|
23
|
+
pricingDimensions?: ModelUsagePricingDimensions;
|
|
24
|
+
};
|
|
25
|
+
export type AsyncAIGCModelQueryResult<TData> = {
|
|
26
|
+
data: TData;
|
|
27
|
+
observation: AIGCModelObservation;
|
|
28
|
+
};
|
|
29
|
+
/** Provider adapter contract for APIs that submit and observe an asynchronous generation task. */
|
|
30
|
+
export interface AsyncAIGCModelClient<TInput = unknown, TData = unknown> {
|
|
31
|
+
submit(input: TInput): Promise<AsyncAIGCModelSubmission<TData>>;
|
|
32
|
+
query(providerRequestId: string, context?: AsyncAIGCModelQueryContext): Promise<AsyncAIGCModelQueryResult<TData>>;
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class ImageGenerationModel extends AIModel {
|
|
35
|
+
abstract getAIGCModel(copilotModel: ICopilotModel, options?: TChatModelOptions): AIGCModelClient;
|
|
36
|
+
}
|
|
37
|
+
export declare abstract class VideoGenerationModel extends AIModel {
|
|
38
|
+
abstract getAIGCModel(copilotModel: ICopilotModel, options?: TChatModelOptions): AsyncAIGCModelClient;
|
|
39
|
+
}
|
|
@@ -4,6 +4,7 @@ export * from './model';
|
|
|
4
4
|
export * from './speech2text';
|
|
5
5
|
export * from './tts';
|
|
6
6
|
export * from './profile';
|
|
7
|
+
export * from './aigc';
|
|
7
8
|
export declare const PROVIDE_AI_MODEL_LLM = "provide_ai_model_llm";
|
|
8
9
|
export declare const PROVIDE_AI_MODEL_MODERATION = "provide_ai_model_moderation";
|
|
9
10
|
export declare const PROVIDE_AI_MODEL_SPEECH2TEXT = "provide_ai_model_speech2text";
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
import { BaseChatModel } from
|
|
2
|
-
import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ParameterType, PriceInfo, PriceType } from
|
|
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';
|
|
3
|
+
export type TModelUsageType = 'estimated';
|
|
4
|
+
export type TLLMUsage = ILLMUsage & {
|
|
5
|
+
type?: TModelUsageType;
|
|
6
|
+
};
|
|
3
7
|
export type TChatModelOptions = {
|
|
4
8
|
modelProperties: Record<string, any>;
|
|
5
9
|
handleLLMTokens: (input: {
|
|
6
10
|
copilot: ICopilot;
|
|
7
11
|
model?: string;
|
|
8
|
-
|
|
12
|
+
requestId?: string;
|
|
13
|
+
usage?: TLLMUsage;
|
|
9
14
|
/**
|
|
10
15
|
* @deprecated use usage
|
|
11
16
|
*/
|
|
12
17
|
tokenUsed?: number;
|
|
13
|
-
}) => void
|
|
18
|
+
}) => void | Promise<void>;
|
|
14
19
|
verbose: boolean;
|
|
15
20
|
};
|
|
16
21
|
export interface IAIModel {
|
|
17
22
|
validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
|
|
18
23
|
getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
|
|
19
24
|
predefinedModels(): AIModelEntity[];
|
|
25
|
+
getUsagePricingSnapshot(model: string, credentials: Record<string, any>, context: ModelUsagePricingContext): ModelUsagePricingSnapshot;
|
|
20
26
|
getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number, inputTokens?: number): PriceInfo;
|
|
21
27
|
}
|
|
22
28
|
export declare const CommonParameterRules: {
|
|
@@ -12,6 +12,8 @@ export interface RuntimeCapabilityRegistry {
|
|
|
12
12
|
get<T>(key: RuntimeCapabilityKey<T> | string): T | undefined;
|
|
13
13
|
require<T>(key: RuntimeCapabilityKey<T> | string): T;
|
|
14
14
|
}
|
|
15
|
+
/** Read-only capability view accepted by plugin-side consumers. */
|
|
16
|
+
export type RuntimeCapabilityResolver = Pick<RuntimeCapabilityRegistry, 'get'>;
|
|
15
17
|
export declare const XPERT_RUNTIME_CAPABILITIES_TOKEN = "XPERT_RUNTIME_CAPABILITIES";
|
|
16
18
|
export declare class DefaultRuntimeCapabilityRegistry implements RuntimeCapabilityRegistry {
|
|
17
19
|
private readonly capabilities;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './provider.decorator';
|
|
2
|
+
export * from './provider.registry';
|
|
3
|
+
export * from './runtime-capability';
|
|
4
|
+
export type { EvolutionBaselineExporter, EvolutionCandidateBuilder, EvolutionProvider, EvolutionReleaseProvider, EvolutionReplayEvaluator, EvolutionTargetProvider } from '@xpert-ai/contracts';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const EVOLUTION_TARGET_PROVIDER = "EVOLUTION_TARGET_PROVIDER";
|
|
2
|
+
export declare const EvolutionTargetProviderStrategy: (providerKey: string) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EvolutionTargetProvider } from '@xpert-ai/contracts';
|
|
2
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
3
|
+
import { BaseStrategyRegistry } from '../strategy';
|
|
4
|
+
export declare class EvolutionTargetProviderRegistry extends BaseStrategyRegistry<EvolutionTargetProvider> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
listDescriptors(organizationId?: string): import("@xpert-ai/contracts").EvolutionTargetDescriptor[];
|
|
7
|
+
}
|
|
@@ -80,6 +80,8 @@ export type ManagedQueueJob<TPayload = unknown> = {
|
|
|
80
80
|
data: TPayload;
|
|
81
81
|
attemptsMade: number;
|
|
82
82
|
opts?: Record<string, unknown>;
|
|
83
|
+
/** Persist a processor checkpoint without changing queue ownership metadata. */
|
|
84
|
+
updateData(data: TPayload): Promise<void>;
|
|
83
85
|
};
|
|
84
86
|
export type ManagedQueueJobContext = {
|
|
85
87
|
pluginName: string;
|
|
@@ -92,7 +94,7 @@ export type ManagedQueueJobContext = {
|
|
|
92
94
|
/** Business actor captured when the logical job was enqueued. */
|
|
93
95
|
userId?: string | null;
|
|
94
96
|
};
|
|
95
|
-
export type ManagedQueueJobSnapshot<TPayload = unknown> = ManagedQueueJob<TPayload> & {
|
|
97
|
+
export type ManagedQueueJobSnapshot<TPayload = unknown> = Omit<ManagedQueueJob<TPayload>, 'updateData'> & {
|
|
96
98
|
state?: string;
|
|
97
99
|
/** BullMQ terminal failure text, when the physical job is in the failed state. */
|
|
98
100
|
failedReason?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONValue } from '@xpert-ai/contracts';
|
|
1
|
+
import { type I18nObject, JSONValue } from '@xpert-ai/contracts';
|
|
2
2
|
export type KnowledgebaseDocumentFile = {
|
|
3
3
|
buffer: Buffer;
|
|
4
4
|
originalname?: string;
|
|
@@ -24,6 +24,7 @@ export type KnowledgebaseDocumentDraft = {
|
|
|
24
24
|
};
|
|
25
25
|
export type KnowledgebaseDocumentRecord = {
|
|
26
26
|
id: string;
|
|
27
|
+
version?: number;
|
|
27
28
|
name?: string;
|
|
28
29
|
type?: string;
|
|
29
30
|
category?: string | null;
|
|
@@ -35,9 +36,63 @@ export type KnowledgebaseDocumentRecord = {
|
|
|
35
36
|
status?: string | null;
|
|
36
37
|
progress?: number | null;
|
|
37
38
|
processMsg?: string | null;
|
|
39
|
+
/** Safe transformer provider key resolved from the document parser configuration. */
|
|
40
|
+
processorType?: string | null;
|
|
41
|
+
/** Localized label declared by the resolved transformer provider. */
|
|
42
|
+
processorLabel?: I18nObject | null;
|
|
38
43
|
knowledgebaseId?: string;
|
|
44
|
+
sourceHash?: string | null;
|
|
45
|
+
contentHash?: string | null;
|
|
46
|
+
tokenNum?: number | null;
|
|
47
|
+
chunkNum?: number | null;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
createdAt?: string;
|
|
50
|
+
updatedAt?: string;
|
|
51
|
+
/** Stable knowledgebase-relative directory containing the document. */
|
|
52
|
+
folderPath?: string | null;
|
|
53
|
+
/** Immediate folder document id when the parent relation was requested. */
|
|
54
|
+
parentId?: string | null;
|
|
39
55
|
metadata?: KnowledgebaseDocumentMetadata;
|
|
40
56
|
};
|
|
57
|
+
export type KnowledgebaseListDocumentsInput = {
|
|
58
|
+
knowledgebaseId: string;
|
|
59
|
+
page?: number;
|
|
60
|
+
pageSize?: number;
|
|
61
|
+
search?: string;
|
|
62
|
+
includeFolders?: boolean;
|
|
63
|
+
/** List direct children of this folder. Use null for the knowledgebase root. */
|
|
64
|
+
parentId?: string | null;
|
|
65
|
+
/** Restrict results to a stable knowledgebase-relative folder path. */
|
|
66
|
+
folderPath?: string;
|
|
67
|
+
/** Defaults to direct. Descendants includes the selected folder and all child folders. */
|
|
68
|
+
folderMode?: 'direct' | 'descendants';
|
|
69
|
+
};
|
|
70
|
+
export type KnowledgebaseListDocumentsResult = {
|
|
71
|
+
documents: KnowledgebaseDocumentRecord[];
|
|
72
|
+
total: number;
|
|
73
|
+
page: number;
|
|
74
|
+
pageSize: number;
|
|
75
|
+
};
|
|
76
|
+
export type KnowledgebaseCreateFolderInput = {
|
|
77
|
+
knowledgebaseId: string;
|
|
78
|
+
name: string;
|
|
79
|
+
parentId?: string | null;
|
|
80
|
+
};
|
|
81
|
+
export type KnowledgebaseCreateFolderResult = {
|
|
82
|
+
knowledgebaseId: string;
|
|
83
|
+
folder: KnowledgebaseDocumentRecord;
|
|
84
|
+
};
|
|
85
|
+
export type KnowledgebaseMoveDocumentInput = {
|
|
86
|
+
knowledgebaseId: string;
|
|
87
|
+
documentId: string;
|
|
88
|
+
parentId?: string | null;
|
|
89
|
+
expectedVersion?: number;
|
|
90
|
+
};
|
|
91
|
+
export type KnowledgebaseMoveDocumentResult = {
|
|
92
|
+
knowledgebaseId: string;
|
|
93
|
+
document: KnowledgebaseDocumentRecord;
|
|
94
|
+
affectedDocumentIds: string[];
|
|
95
|
+
};
|
|
41
96
|
export type KnowledgebaseUploadFileInput = {
|
|
42
97
|
knowledgebaseId: string;
|
|
43
98
|
file: KnowledgebaseDocumentFile;
|
|
@@ -111,6 +166,9 @@ export type KnowledgebaseDeleteDocumentsResult = {
|
|
|
111
166
|
missingDocumentIds?: string[];
|
|
112
167
|
};
|
|
113
168
|
export interface KnowledgebaseDocumentsApi {
|
|
169
|
+
listDocuments(input: KnowledgebaseListDocumentsInput): Promise<KnowledgebaseListDocumentsResult>;
|
|
170
|
+
createFolder(input: KnowledgebaseCreateFolderInput): Promise<KnowledgebaseCreateFolderResult>;
|
|
171
|
+
moveDocument(input: KnowledgebaseMoveDocumentInput): Promise<KnowledgebaseMoveDocumentResult>;
|
|
114
172
|
uploadFile(input: KnowledgebaseUploadFileInput): Promise<KnowledgebaseUploadedFile>;
|
|
115
173
|
importArchive(input: KnowledgebaseImportArchiveInput): Promise<KnowledgebaseImportArchiveResult>;
|
|
116
174
|
createDocuments(input: KnowledgebaseCreateDocumentsInput): Promise<KnowledgebaseCreateDocumentsResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONValue } from '@xpert-ai/contracts';
|
|
1
|
+
import { JSONValue, KnowledgeFilterDiagnostics, KnowledgeFilterNode } from '@xpert-ai/contracts';
|
|
2
2
|
export type KnowledgebaseRetrievalMode = 'vector' | 'graph' | 'hybrid';
|
|
3
3
|
export type KnowledgebaseMetadata = Record<string, JSONValue>;
|
|
4
4
|
export type KnowledgebaseRetrievalSettings = {
|
|
@@ -15,7 +15,7 @@ export type KnowledgebaseSearchInput = {
|
|
|
15
15
|
query: string;
|
|
16
16
|
k?: number;
|
|
17
17
|
score?: number;
|
|
18
|
-
filter?:
|
|
18
|
+
filter?: KnowledgeFilterNode;
|
|
19
19
|
retrieval?: KnowledgebaseRetrievalSettings;
|
|
20
20
|
source: string;
|
|
21
21
|
requestId?: string;
|
|
@@ -25,6 +25,10 @@ export type KnowledgebaseDocument = {
|
|
|
25
25
|
pageContent: string;
|
|
26
26
|
metadata?: Record<string, unknown>;
|
|
27
27
|
};
|
|
28
|
+
export type KnowledgebaseSearchResult = {
|
|
29
|
+
documents: KnowledgebaseDocument[];
|
|
30
|
+
diagnostics: KnowledgeFilterDiagnostics[];
|
|
31
|
+
};
|
|
28
32
|
export type KnowledgebaseListInput = {
|
|
29
33
|
workspaceId?: string | null;
|
|
30
34
|
published?: boolean;
|
|
@@ -55,12 +59,27 @@ export type KnowledgebaseWriteChunkInput = {
|
|
|
55
59
|
title?: string;
|
|
56
60
|
metadata?: KnowledgebaseMetadata;
|
|
57
61
|
writeKey: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional system-managed document target. When omitted, the chunk is written to the
|
|
64
|
+
* Agent's shared writer document for backwards compatibility. A stable key creates an
|
|
65
|
+
* independently managed document that can be placed in a knowledgebase folder.
|
|
66
|
+
*/
|
|
67
|
+
document?: {
|
|
68
|
+
key: string;
|
|
69
|
+
name: string;
|
|
70
|
+
parentId?: string | null;
|
|
71
|
+
metadata?: KnowledgebaseMetadata;
|
|
72
|
+
};
|
|
58
73
|
executionId?: string;
|
|
59
74
|
threadId?: string;
|
|
60
75
|
};
|
|
61
76
|
export type KnowledgebaseWriteChunkResult = {
|
|
62
77
|
status?: 'created' | 'skipped';
|
|
63
78
|
chunkId?: string;
|
|
79
|
+
knowledgebaseId?: string;
|
|
80
|
+
knowledgebaseName?: string;
|
|
81
|
+
documentId?: string;
|
|
82
|
+
writeKey?: string;
|
|
64
83
|
message?: string;
|
|
65
84
|
};
|
|
66
85
|
export type KnowledgebaseDeleteChunksInput = {
|
|
@@ -70,6 +89,10 @@ export type KnowledgebaseDeleteChunksInput = {
|
|
|
70
89
|
knowledgebaseId: string;
|
|
71
90
|
writeKeys?: string[];
|
|
72
91
|
writeKeyPrefix?: string;
|
|
92
|
+
/** Restrict deletion to a dedicated system-managed document created by writeChunk. */
|
|
93
|
+
documentKey?: string;
|
|
94
|
+
/** Remove the managed document after deletion when it has no chunks left. */
|
|
95
|
+
deleteDocumentIfEmpty?: boolean;
|
|
73
96
|
};
|
|
74
97
|
export type KnowledgebaseDeleteChunksResult = {
|
|
75
98
|
deletedCount: number;
|
|
@@ -77,11 +100,80 @@ export type KnowledgebaseDeleteChunksResult = {
|
|
|
77
100
|
documentId?: string;
|
|
78
101
|
writeKeys?: string[];
|
|
79
102
|
writeKeyPrefix?: string;
|
|
103
|
+
documentDeleted?: boolean;
|
|
104
|
+
};
|
|
105
|
+
export type KnowledgebaseProvisioningPermission = 'private' | 'organization' | 'public';
|
|
106
|
+
export type KnowledgebaseProvisioningMetadataField = {
|
|
107
|
+
key: string;
|
|
108
|
+
label?: {
|
|
109
|
+
en_US?: string;
|
|
110
|
+
zh_Hans?: string;
|
|
111
|
+
};
|
|
112
|
+
type: 'string' | 'number' | 'boolean' | 'enum' | 'datetime' | 'string[]' | 'number[]' | 'object';
|
|
113
|
+
scope?: 'document' | 'chunk';
|
|
114
|
+
enumValues?: string[];
|
|
115
|
+
description?: string;
|
|
116
|
+
};
|
|
117
|
+
export type KnowledgebaseProvisioningSpec = {
|
|
118
|
+
key: string;
|
|
119
|
+
name: string;
|
|
120
|
+
description: string;
|
|
121
|
+
permission: KnowledgebaseProvisioningPermission;
|
|
122
|
+
language?: 'Chinese' | 'English';
|
|
123
|
+
chunkSize?: number;
|
|
124
|
+
chunkOverlap?: number;
|
|
125
|
+
delimiter?: string;
|
|
126
|
+
topK?: number;
|
|
127
|
+
score?: number;
|
|
128
|
+
metadataSchema?: KnowledgebaseProvisioningMetadataField[];
|
|
129
|
+
incrementalSyncEnabled?: boolean;
|
|
80
130
|
};
|
|
131
|
+
export type KnowledgebaseEnsureInput = {
|
|
132
|
+
workspaceId: string;
|
|
133
|
+
namespace: string;
|
|
134
|
+
/**
|
|
135
|
+
* Reuse the most recently updated accessible knowledgebase embedding-model configuration when
|
|
136
|
+
* creating a managed set. This keeps one-click provisioning usable without exposing provider
|
|
137
|
+
* credentials to plugins. Provisioning fails explicitly when no configured model is available.
|
|
138
|
+
*/
|
|
139
|
+
inheritEmbeddingModel?: boolean;
|
|
140
|
+
knowledgebases: KnowledgebaseProvisioningSpec[];
|
|
141
|
+
};
|
|
142
|
+
export type KnowledgebaseEnsureItem = KnowledgebaseListItem & {
|
|
143
|
+
key: string;
|
|
144
|
+
operation: 'created' | 'updated';
|
|
145
|
+
};
|
|
146
|
+
export type KnowledgebaseEnsureResult = {
|
|
147
|
+
namespace: string;
|
|
148
|
+
workspaceId: string;
|
|
149
|
+
knowledgebases: KnowledgebaseEnsureItem[];
|
|
150
|
+
};
|
|
151
|
+
export type KnowledgebaseConnectAgentInput = {
|
|
152
|
+
workspaceId: string;
|
|
153
|
+
xpertId: string;
|
|
154
|
+
agentKey: string;
|
|
155
|
+
knowledgebaseIds: string[];
|
|
156
|
+
/** Optional administrator-owned retrieval policies keyed by knowledgebase id. */
|
|
157
|
+
retrievals?: Record<string, KnowledgebaseRetrievalSettings & {
|
|
158
|
+
fixedFilter?: KnowledgeFilterNode;
|
|
159
|
+
allowAgentFilter?: boolean;
|
|
160
|
+
}>;
|
|
161
|
+
};
|
|
162
|
+
export type KnowledgebaseConnectAgentResult = {
|
|
163
|
+
xpertId: string;
|
|
164
|
+
agentKey: string;
|
|
165
|
+
knowledgebaseIds: string[];
|
|
166
|
+
addedKnowledgebaseIds: string[];
|
|
167
|
+
};
|
|
168
|
+
export interface KnowledgebaseProvisioningApi {
|
|
169
|
+
ensure(input: KnowledgebaseEnsureInput): Promise<KnowledgebaseEnsureResult>;
|
|
170
|
+
connectAgent(input: KnowledgebaseConnectAgentInput): Promise<KnowledgebaseConnectAgentResult>;
|
|
171
|
+
}
|
|
81
172
|
export interface KnowledgebaseApi {
|
|
82
173
|
list(input: KnowledgebaseListInput): Promise<KnowledgebaseListItem[]>;
|
|
83
|
-
search(input: KnowledgebaseSearchInput): Promise<
|
|
174
|
+
search(input: KnowledgebaseSearchInput): Promise<KnowledgebaseSearchResult>;
|
|
84
175
|
writeChunk(input: KnowledgebaseWriteChunkInput): Promise<KnowledgebaseWriteChunkResult>;
|
|
85
176
|
deleteChunks(input: KnowledgebaseDeleteChunksInput): Promise<KnowledgebaseDeleteChunksResult>;
|
|
86
177
|
}
|
|
87
178
|
export declare const KnowledgebaseRuntimeCapability: import("../../core/runtime-capability").RuntimeCapabilityKey<KnowledgebaseApi>;
|
|
179
|
+
export declare const KnowledgebaseProvisioningRuntimeCapability: import("../../core/runtime-capability").RuntimeCapabilityKey<KnowledgebaseProvisioningApi>;
|
|
@@ -228,4 +228,9 @@ export interface WorkspaceFilesApi {
|
|
|
228
228
|
reference: WorkspacePortableFileReference;
|
|
229
229
|
}>;
|
|
230
230
|
}
|
|
231
|
+
/** Workspace file operations used by media generation tools. */
|
|
232
|
+
export type WorkspaceMediaFilesApi<TLocator extends WorkspaceFileLocator = WorkspaceFileLocator> = Pick<WorkspaceFilesApi, 'uploadBuffer' | 'readBuffer'> & {
|
|
233
|
+
readRuntimeBuffer?: (input: TLocator) => Promise<WorkspaceFileBuffer>;
|
|
234
|
+
deleteFile?: WorkspaceFilesApi['deleteFile'];
|
|
235
|
+
};
|
|
231
236
|
export declare const WorkspaceFilesRuntimeCapability: import("../../core/runtime-capability").RuntimeCapabilityKey<WorkspaceFilesApi>;
|
|
@@ -4,13 +4,38 @@ import { I18nObject, IXpertToolset, ToolProviderCredentials, TToolCredentials, T
|
|
|
4
4
|
import { Logger } from '@nestjs/common';
|
|
5
5
|
import { CommandBus, QueryBus } from '@nestjs/cqrs';
|
|
6
6
|
import { BaseToolset } from './toolset';
|
|
7
|
+
import type { AgentMiddlewareModelProviderConnection, AgentMiddlewareRuntimeApi } from '../agent/middleware/runtime';
|
|
8
|
+
import type { ManagedQueueService } from '../managed-queue';
|
|
7
9
|
/**
|
|
8
10
|
* The context params of creating toolset
|
|
9
11
|
*/
|
|
12
|
+
export type TToolTokenUsage = {
|
|
13
|
+
type?: 'estimated';
|
|
14
|
+
requestId: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
promptTokens: number;
|
|
18
|
+
completionTokens: number;
|
|
19
|
+
totalTokens: number;
|
|
20
|
+
};
|
|
21
|
+
export type TToolModelUsageReporter = (usage: TToolTokenUsage) => void | Promise<void>;
|
|
22
|
+
export type TToolModelProviderRuntime = AgentMiddlewareModelProviderConnection;
|
|
23
|
+
export type TToolModelRuntime = {
|
|
24
|
+
/** Use the host's configured model provider; tool plugins must not handle provider API keys. */
|
|
25
|
+
createModelClient: AgentMiddlewareRuntimeApi['createModelClient'];
|
|
26
|
+
/** Resolve the host model provider account required by a direct Provider API tool. */
|
|
27
|
+
getModelProvider?: (provider: string) => Promise<TToolModelProviderRuntime>;
|
|
28
|
+
/** Report usage only for model APIs called directly by the tool. */
|
|
29
|
+
reportUsage?: TToolModelUsageReporter;
|
|
30
|
+
};
|
|
10
31
|
export type TBuiltinToolsetParams = TToolsetParams & {
|
|
11
32
|
commandBus: CommandBus;
|
|
12
33
|
queryBus: QueryBus;
|
|
13
34
|
store?: BaseStore;
|
|
35
|
+
modelRuntime?: TToolModelRuntime;
|
|
36
|
+
managedQueue?: ManagedQueueService;
|
|
37
|
+
/** Installation scope used to route jobs back to this plugin instance. */
|
|
38
|
+
pluginScopeKey?: string;
|
|
14
39
|
};
|
|
15
40
|
export interface IBuiltinToolset {
|
|
16
41
|
validateCredentials(credentials: TToolCredentials): Promise<void>;
|
|
@@ -30,6 +55,9 @@ export declare abstract class BuiltinToolset<T extends StructuredToolInterface =
|
|
|
30
55
|
get commandBus(): CommandBus<import("@nestjs/cqrs").ICommand>;
|
|
31
56
|
get queryBus(): QueryBus<import("@nestjs/cqrs").IQuery>;
|
|
32
57
|
get xpertId(): string;
|
|
58
|
+
get modelRuntime(): TToolModelRuntime;
|
|
59
|
+
get managedQueue(): ManagedQueueService;
|
|
60
|
+
get pluginScopeKey(): string;
|
|
33
61
|
constructor(providerName: string, toolset?: IXpertToolset, params?: TBuiltinToolsetParams);
|
|
34
62
|
validateCredentials(credentials: C): Promise<void>;
|
|
35
63
|
_validateCredentials(credentials: C): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
2
|
+
import { type IXpertToolset, type TToolCredentials } from '@xpert-ai/contracts';
|
|
3
|
+
import { type AIGCModelClient, type AsyncAIGCModelClient } from '../ai-model';
|
|
4
|
+
import { type RuntimeCapabilityResolver, type WorkspaceFileScope, type WorkspaceFilesApi } from '../runtime';
|
|
5
|
+
import { BuiltinToolset, type TBuiltinToolsetParams, type TToolModelProviderRuntime } from './builtin';
|
|
6
|
+
export type ModelProviderAuthorizationScheme = 'Bearer' | 'ApiKey';
|
|
7
|
+
export type ModelProviderBuiltinToolsetOptions = {
|
|
8
|
+
toolsetProviderName: string;
|
|
9
|
+
modelProviderName: string;
|
|
10
|
+
authorizationScheme: ModelProviderAuthorizationScheme;
|
|
11
|
+
invalidCredentialsMessage: string;
|
|
12
|
+
missingProviderMessage: string;
|
|
13
|
+
missingWorkspaceMessage: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Shared host-runtime plumbing for built-in tools backed by a configured model provider.
|
|
17
|
+
* Provider request/response semantics remain owned by each plugin.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class ModelProviderBuiltinToolset<T extends StructuredToolInterface = StructuredToolInterface, C = TToolCredentials> extends BuiltinToolset<T, C> {
|
|
20
|
+
private readonly modelProviderOptions;
|
|
21
|
+
private readonly runtimeCapabilities?;
|
|
22
|
+
private modelProvider?;
|
|
23
|
+
constructor(modelProviderOptions: ModelProviderBuiltinToolsetOptions, toolset?: IXpertToolset, runtimeCapabilities?: RuntimeCapabilityResolver, params?: TBuiltinToolsetParams);
|
|
24
|
+
_validateCredentials(_credentials: C): Promise<void>;
|
|
25
|
+
protected getModelProviderRuntime(): Promise<TToolModelProviderRuntime>;
|
|
26
|
+
protected getModelProviderCredential(modelProvider: TToolModelProviderRuntime): string;
|
|
27
|
+
protected getWorkspaceFiles(): WorkspaceFilesApi;
|
|
28
|
+
protected createWorkspaceScope(): WorkspaceFileScope | undefined;
|
|
29
|
+
protected createAsyncModelClient<TInput, TData>(model: string, modality: 'image' | 'video', purpose?: 'invoke' | 'observe'): Promise<AsyncAIGCModelClient<TInput, TData>>;
|
|
30
|
+
protected createModelClient<TInput, TData>(model: string, modality: 'image' | 'video'): Promise<AIGCModelClient<TInput, TData>>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/ai-model/model-provider-http-client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/toolset/model-provider';
|