@xpert-ai/plugin-sdk 3.6.7 → 3.7.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 (43) hide show
  1. package/SCHEMA_SPECIFICATION.md +2 -1
  2. package/index.cjs.js +1278 -241
  3. package/index.esm.js +1270 -243
  4. package/package.json +2 -1
  5. package/src/index.d.ts +2 -0
  6. package/src/lib/agent/index.d.ts +1 -0
  7. package/src/lib/agent/middleware/index.d.ts +5 -0
  8. package/src/lib/agent/middleware/runtime.d.ts +57 -0
  9. package/src/lib/agent/middleware/strategy.decorator.d.ts +2 -0
  10. package/src/lib/agent/middleware/strategy.interface.d.ts +16 -0
  11. package/src/lib/agent/middleware/strategy.registry.d.ts +6 -0
  12. package/src/lib/agent/middleware/types.d.ts +251 -0
  13. package/src/lib/agent/skill/index.d.ts +3 -0
  14. package/src/lib/agent/skill/skill-source-provider.decorator.d.ts +2 -0
  15. package/src/lib/agent/skill/skill-source-provider.interface.d.ts +23 -0
  16. package/src/lib/agent/skill/skill-source-provider.registry.d.ts +6 -0
  17. package/src/lib/ai-model/commands/create-model-client.command.d.ts +21 -0
  18. package/src/lib/ai-model/commands/index.d.ts +1 -0
  19. package/src/lib/ai-model/index.d.ts +1 -0
  20. package/src/lib/ai-model/types/index.d.ts +1 -0
  21. package/src/lib/ai-model/types/model.d.ts +2 -1
  22. package/src/lib/ai-model/types/profile.d.ts +172 -0
  23. package/src/lib/core/index.d.ts +2 -0
  24. package/src/lib/core/strategy-bus.d.ts +17 -0
  25. package/src/lib/core/types.d.ts +16 -0
  26. package/src/lib/data/datasource/strategy.decorator.d.ts +1 -1
  27. package/src/lib/data/datasource/types.d.ts +29 -1
  28. package/src/lib/integration/strategy.decorator.d.ts +1 -1
  29. package/src/lib/rag/image/strategy.decorator.d.ts +1 -1
  30. package/src/lib/rag/knowledge/knowledge-strategy.decorator.d.ts +1 -1
  31. package/src/lib/rag/retriever/strategy.decorator.d.ts +1 -1
  32. package/src/lib/rag/source/strategy.decorator.d.ts +1 -1
  33. package/src/lib/rag/textsplitter/strategy.decorator.d.ts +1 -1
  34. package/src/lib/rag/transformer/strategy.decorator.d.ts +1 -1
  35. package/src/lib/strategy.d.ts +29 -3
  36. package/src/lib/toolset/strategy.decorator.d.ts +1 -1
  37. package/src/lib/types.d.ts +4 -0
  38. package/src/lib/vectorstore/strategy.decorator.d.ts +1 -1
  39. package/src/lib/workflow/commands/index.d.ts +1 -0
  40. package/src/lib/workflow/commands/wrap-workflow-node-execution.command.d.ts +26 -0
  41. package/src/lib/workflow/index.d.ts +1 -0
  42. package/src/lib/workflow/node/strategy.decorator.d.ts +1 -1
  43. package/src/lib/workflow/trigger/strategy.decorator.d.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-sdk",
3
- "version": "3.6.7",
3
+ "version": "3.7.1",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,7 @@
22
22
  "@metad/contracts": "*",
23
23
  "@nestjs/common": "*",
24
24
  "@nestjs/core": "*",
25
+ "@nestjs/cqrs": "*",
25
26
  "lodash-es": "*",
26
27
  "i18next-fs-backend": "*",
27
28
  "i18next": "*",
package/src/index.d.ts CHANGED
@@ -11,3 +11,5 @@ export * from './lib/toolset/index';
11
11
  export * from './lib/core/index';
12
12
  export * from './lib/data/index';
13
13
  export * from './lib/ai-model/index';
14
+ export * from './lib/agent/index';
15
+ export * from './lib/strategy';
@@ -0,0 +1 @@
1
+ export * from './middleware';
@@ -0,0 +1,5 @@
1
+ export * from './strategy.decorator';
2
+ export * from './strategy.interface';
3
+ export * from './strategy.registry';
4
+ export * from './types';
5
+ export * from './runtime';
@@ -0,0 +1,57 @@
1
+ import type { Runtime as LangGraphRuntime } from "@langchain/langgraph";
2
+ import type { BaseMessage } from "@langchain/core/messages";
3
+ /**
4
+ * Type for the agent's built-in state properties.
5
+ */
6
+ export type AgentBuiltInState = {
7
+ /**
8
+ * Array of messages representing the conversation history.
9
+ *
10
+ * This includes all messages exchanged during the agent's execution:
11
+ * - Human messages: Input from the user
12
+ * - AI messages: Responses from the language model
13
+ * - Tool messages: Results from tool executions
14
+ * - System messages: System-level instructions or information
15
+ *
16
+ * Messages are accumulated throughout the agent's lifecycle and can be
17
+ * accessed or modified by middleware hooks during execution.
18
+ */
19
+ messages: BaseMessage[];
20
+ /**
21
+ * Structured response data returned by the agent when a `responseFormat` is configured.
22
+ *
23
+ * This property is only populated when you provide a `responseFormat` schema
24
+ * (as Zod or JSON schema) to the agent configuration. The agent will format
25
+ * its final output to match the specified schema and store it in this property.
26
+ *
27
+ * Note: The type is specified as `Record<string, unknown>` because TypeScript cannot
28
+ * infer the actual response format type in contexts like middleware, where the agent's
29
+ * generic type parameters are not accessible. You may need to cast this to your specific
30
+ * response type when accessing it.
31
+ */
32
+ structuredResponse?: Record<string, unknown>;
33
+ };
34
+ /**
35
+ * Type helper to check if TContext is an optional Zod schema
36
+ */
37
+ type IsOptionalZodObject<T> = T extends any ? true : false;
38
+ type IsDefaultZodObject<T> = T extends any ? true : false;
39
+ export type WithMaybeContext<TContext> = undefined extends TContext ? {
40
+ readonly context?: TContext;
41
+ } : IsOptionalZodObject<TContext> extends true ? {
42
+ readonly context?: TContext;
43
+ } : IsDefaultZodObject<TContext> extends true ? {
44
+ readonly context?: TContext;
45
+ } : {
46
+ readonly context: TContext;
47
+ };
48
+ /**
49
+ * Runtime information available to middleware (readonly).
50
+ */
51
+ export type Runtime<TContext = unknown> = Partial<Omit<LangGraphRuntime<TContext>, "context" | "configurable">> & WithMaybeContext<TContext> & {
52
+ configurable?: {
53
+ thread_id?: string;
54
+ [key: string]: unknown;
55
+ };
56
+ };
57
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const AGENT_MIDDLEWARE_STRATEGY = "AGENT_MIDDLEWARE_STRATEGY";
2
+ export declare const AgentMiddlewareStrategy: (provider: string) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,16 @@
1
+ import { IWFNMiddleware, TAgentMiddlewareMeta } from '@metad/contracts';
2
+ import { AgentMiddleware, PromiseOrValue } from './types';
3
+ export interface IAgentMiddlewareContext {
4
+ tenantId: string;
5
+ userId: string;
6
+ workspaceId?: string;
7
+ projectId?: string;
8
+ conversationId?: string;
9
+ xpertId?: string;
10
+ agentKey?: string;
11
+ node: IWFNMiddleware;
12
+ }
13
+ export interface IAgentMiddlewareStrategy<T = unknown> {
14
+ meta: TAgentMiddlewareMeta;
15
+ createMiddleware(options: T, context: IAgentMiddlewareContext): PromiseOrValue<AgentMiddleware>;
16
+ }
@@ -0,0 +1,6 @@
1
+ import { DiscoveryService, Reflector } from '@nestjs/core';
2
+ import { BaseStrategyRegistry } from '../../strategy';
3
+ import { IAgentMiddlewareStrategy } from './strategy.interface';
4
+ export declare class AgentMiddlewareRegistry extends BaseStrategyRegistry<IAgentMiddlewareStrategy> {
5
+ constructor(discoveryService: DiscoveryService, reflector: Reflector);
6
+ }
@@ -0,0 +1,251 @@
1
+ import { LanguageModelLike } from '@langchain/core/language_models/base';
2
+ import { AIMessage, BaseMessage, SystemMessage } from '@langchain/core/messages';
3
+ import { DynamicStructuredTool } from '@langchain/core/tools';
4
+ import { InteropZodObject } from '@langchain/core/utils/types';
5
+ import { Runtime } from './runtime';
6
+ /**
7
+ * jump targets (user facing)
8
+ */
9
+ export declare const JUMP_TO_TARGETS: readonly ["model", "tools", "end"];
10
+ export type JumpToTarget = (typeof JUMP_TO_TARGETS)[number];
11
+ export type PromiseOrValue<T> = T | Promise<T>;
12
+ /**
13
+ * Result type for middleware functions.
14
+ */
15
+ export type MiddlewareResult<TState> = (TState & {
16
+ jumpTo?: JumpToTarget;
17
+ }) | void;
18
+ /**
19
+ * Handler function type for the beforeAgent hook.
20
+ * Called once at the start of agent invocation before any model calls or tool executions.
21
+ *
22
+ * @param state - The current agent state (includes both middleware state and built-in state)
23
+ * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
24
+ * @returns A middleware result containing partial state updates or undefined to pass through
25
+ */
26
+ type BeforeAgentHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
27
+ /**
28
+ * Hook type for the beforeAgent lifecycle event.
29
+ * Can be either a handler function or an object with a handler and optional jump targets.
30
+ * This hook is called once at the start of the agent invocation.
31
+ */
32
+ export type BeforeAgentHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeAgentHandler<TSchema, TContext> | {
33
+ hook: BeforeAgentHandler<TSchema, TContext>;
34
+ canJumpTo?: JumpToTarget[];
35
+ };
36
+ /**
37
+ * Handler function type for the beforeModel hook.
38
+ * Called before the model is invoked and before the wrapModelCall hook.
39
+ *
40
+ * @param state - The current agent state (includes both middleware state and built-in state)
41
+ * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
42
+ * @returns A middleware result containing partial state updates or undefined to pass through
43
+ */
44
+ export type BeforeModelHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
45
+ /**
46
+ * Hook type for the beforeModel lifecycle event.
47
+ * Can be either a handler function or an object with a handler and optional jump targets.
48
+ * This hook is called before each model invocation.
49
+ */
50
+ export type BeforeModelHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeModelHandler<TSchema, TContext> | {
51
+ hook: BeforeModelHandler<TSchema, TContext>;
52
+ canJumpTo?: JumpToTarget[];
53
+ };
54
+ /**
55
+ * Handler function type for the afterModel hook.
56
+ * Called after the model is invoked and before any tools are called.
57
+ * Allows modifying the agent state after model invocation, e.g., to update tool call parameters.
58
+ *
59
+ * @param state - The current agent state (includes both middleware state and built-in state)
60
+ * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
61
+ * @returns A middleware result containing partial state updates or undefined to pass through
62
+ */
63
+ export type AfterModelHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
64
+ /**
65
+ * Hook type for the afterModel lifecycle event.
66
+ * Can be either a handler function or an object with a handler and optional jump targets.
67
+ * This hook is called after each model invocation.
68
+ */
69
+ export type AfterModelHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterModelHandler<TSchema, TContext> | {
70
+ hook: AfterModelHandler<TSchema, TContext>;
71
+ canJumpTo?: JumpToTarget[];
72
+ };
73
+ /**
74
+ * Handler function type for the afterAgent hook.
75
+ * Called once at the end of agent invocation after all model calls and tool executions are complete.
76
+ *
77
+ * @param state - The current agent state (includes both middleware state and built-in state)
78
+ * @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
79
+ * @returns A middleware result containing partial state updates or undefined to pass through
80
+ */
81
+ type AfterAgentHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
82
+ /**
83
+ * Hook type for the afterAgent lifecycle event.
84
+ * Can be either a handler function or an object with a handler and optional jump targets.
85
+ * This hook is called once at the end of the agent invocation.
86
+ */
87
+ export type AfterAgentHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterAgentHandler<TSchema, TContext> | {
88
+ hook: AfterAgentHandler<TSchema, TContext>;
89
+ canJumpTo?: JumpToTarget[];
90
+ };
91
+ /**
92
+ * Configuration for modifying a model call at runtime.
93
+ * All fields are optional and only provided fields will override defaults.
94
+ *
95
+ * @template TState - The agent's state type, must extend Record<string, unknown>. Defaults to Record<string, unknown>.
96
+ * @template TContext - The runtime context type for accessing metadata and control flow. Defaults to unknown.
97
+ */
98
+ export interface ModelRequest<TState = any, TContext = unknown> {
99
+ /**
100
+ * The model to use for this step.
101
+ */
102
+ model: LanguageModelLike;
103
+ /**
104
+ * The messages to send to the model.
105
+ */
106
+ messages: BaseMessage[];
107
+ systemMessage?: SystemMessage;
108
+ runtime: Runtime<TContext>;
109
+ }
110
+ /**
111
+ * Handler function type for wrapping model calls.
112
+ * Takes a model request and returns the AI message response.
113
+ *
114
+ * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime
115
+ * @returns The AI message response from the model
116
+ */
117
+ export type WrapModelCallHandler<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema, TContext>) => PromiseOrValue<AIMessage>;
118
+ /**
119
+ * Wrapper function type for the wrapModelCall hook.
120
+ * Allows middleware to intercept and modify model execution.
121
+ * This enables you to:
122
+ * - Modify the request before calling the model (e.g., change system prompt, add/remove tools)
123
+ * - Handle errors and retry with different parameters
124
+ * - Post-process the response
125
+ * - Implement custom caching, logging, or other cross-cutting concerns
126
+ *
127
+ * @param request - The model request containing all parameters needed for the model call
128
+ * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response
129
+ * @returns The AI message response from the model (or a modified version)
130
+ */
131
+ export type WrapModelCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema, TContext>, handler: WrapModelCallHandler<TSchema, TContext>) => PromiseOrValue<AIMessage>;
132
+ export interface AgentMiddleware<TSchema extends InteropZodObject | undefined = any, TContextSchema extends InteropZodObject | undefined = any, TFullContext = any> {
133
+ /**
134
+ * The name of the middleware.
135
+ */
136
+ name: string;
137
+ /**
138
+ * The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:
139
+ * - A Zod object
140
+ * - A Zod optional object
141
+ * - A Zod default object
142
+ * - Undefined
143
+ */
144
+ stateSchema?: TSchema;
145
+ /**
146
+ * The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:
147
+ * - A Zod object
148
+ * - A Zod optional object
149
+ * - A Zod default object
150
+ * - Undefined
151
+ */
152
+ contextSchema?: TContextSchema;
153
+ tools?: DynamicStructuredTool[];
154
+ beforeAgent?: BeforeAgentHook<TSchema, TFullContext>;
155
+ beforeModel?: BeforeModelHook<TSchema, TFullContext>;
156
+ afterModel?: AfterModelHook<TSchema, TFullContext>;
157
+ afterAgent?: AfterAgentHook<TSchema, TFullContext>;
158
+ /**
159
+ * Wraps the model invocation with custom logic. This allows you to:
160
+ * - Modify the request before calling the model
161
+ * - Handle errors and retry with different parameters
162
+ * - Post-process the response
163
+ * - Implement custom caching, logging, or other cross-cutting concerns
164
+ *
165
+ * @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime.
166
+ * @param handler - The function that invokes the model. Call this with a ModelRequest to get the response.
167
+ * @returns The response from the model (or a modified version).
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * wrapModelCall: async (request, handler) => {
172
+ * // Modify request before calling
173
+ * const modifiedRequest = { ...request, systemPrompt: "You are helpful" };
174
+ *
175
+ * try {
176
+ * // Call the model
177
+ * return await handler(modifiedRequest);
178
+ * } catch (error) {
179
+ * // Handle errors and retry with fallback
180
+ * const fallbackRequest = { ...request, model: fallbackModel };
181
+ * return await handler(fallbackRequest);
182
+ * }
183
+ * }
184
+ * ```
185
+ */
186
+ wrapModelCall?: WrapModelCallHook<TSchema, TFullContext>;
187
+ /**
188
+ * Wraps tool execution with custom logic. This allows you to:
189
+ * - Modify tool call parameters before execution
190
+ * - Handle errors and retry with different parameters
191
+ * - Post-process tool results
192
+ * - Implement caching, logging, authentication, or other cross-cutting concerns
193
+ * - Return Command objects for advanced control flow
194
+ *
195
+ * The handler receives a ToolCallRequest containing the tool call, state, and runtime,
196
+ * along with a handler function to execute the actual tool.
197
+ *
198
+ * @param request - The tool call request containing toolCall, state, and runtime.
199
+ * @param handler - The function that executes the tool. Call this with a ToolCallRequest to get the result.
200
+ * @returns The tool result as a ToolMessage or a Command for advanced control flow.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * wrapToolCall: async (request, handler) => {
205
+ * console.log(`Calling tool: ${request.tool.name}`);
206
+ * console.log(`Tool description: ${request.tool.description}`);
207
+ *
208
+ * try {
209
+ * // Execute the tool
210
+ * const result = await handler(request);
211
+ * console.log(`Tool ${request.tool.name} succeeded`);
212
+ * return result;
213
+ * } catch (error) {
214
+ * console.error(`Tool ${request.tool.name} failed:`, error);
215
+ * // Could return a custom error message or retry
216
+ * throw error;
217
+ * }
218
+ * }
219
+ * ```
220
+ *
221
+ * @example Authentication
222
+ * ```ts
223
+ * wrapToolCall: async (request, handler) => {
224
+ * // Check if user is authorized for this tool
225
+ * if (!request.runtime.context.isAuthorized(request.tool.name)) {
226
+ * return new ToolMessage({
227
+ * content: "Unauthorized to call this tool",
228
+ * tool_call_id: request.toolCall.id,
229
+ * });
230
+ * }
231
+ * return handler(request);
232
+ * }
233
+ * ```
234
+ *
235
+ * @example Caching
236
+ * ```ts
237
+ * const cache = new Map();
238
+ * wrapToolCall: async (request, handler) => {
239
+ * const cacheKey = `${request.tool.name}:${JSON.stringify(request.toolCall.args)}`;
240
+ * if (cache.has(cacheKey)) {
241
+ * return cache.get(cacheKey);
242
+ * }
243
+ * const result = await handler(request);
244
+ * cache.set(cacheKey, result);
245
+ * return result;
246
+ * }
247
+ * ```
248
+ */
249
+ wrapToolCall?: (request: ModelRequest<TSchema, TFullContext>, handler: WrapModelCallHandler<TSchema, TFullContext>) => PromiseOrValue<AIMessage>;
250
+ }
251
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './skill-source-provider.interface';
2
+ export * from './skill-source-provider.registry';
3
+ export * from './skill-source-provider.decorator';
@@ -0,0 +1,2 @@
1
+ export declare const SKILL_SOURCE_PROVIDER = "SKILL_SOURCE_PROVIDER";
2
+ export declare const SkillSourceProviderStrategy: (provider: string) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -0,0 +1,23 @@
1
+ import { ISkillRepository, ISkillRepositoryIndex, TSkillSourceMeta } from "@metad/contracts";
2
+ export interface ISkillSourceProvider {
3
+ type: string;
4
+ meta: TSkillSourceMeta;
5
+ /**
6
+ * Whether the provider can handle a given source type
7
+ */
8
+ canHandle(sourceType: string): boolean;
9
+ /**
10
+ * List skill index entries from a source
11
+ */
12
+ listSkills(config: ISkillRepository): Promise<ISkillRepositoryIndex[]>;
13
+ /**
14
+ * Fetch a concrete skill package into a temporary directory
15
+ */
16
+ installSkillPackage(index: ISkillRepositoryIndex, installDir: string): Promise<string>;
17
+ /**
18
+ * Uninstall a skill package from a given path.
19
+ *
20
+ * @param path
21
+ */
22
+ uninstallSkillPackage(path: string): Promise<void>;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { DiscoveryService, Reflector } from '@nestjs/core';
2
+ import { BaseStrategyRegistry } from '../../strategy';
3
+ import { ISkillSourceProvider } from './skill-source-provider.interface';
4
+ export declare class SkillSourceProviderRegistry extends BaseStrategyRegistry<ISkillSourceProvider> {
5
+ constructor(discoveryService: DiscoveryService, reflector: Reflector);
6
+ }
@@ -0,0 +1,21 @@
1
+ import { Embeddings } from '@langchain/core/embeddings';
2
+ import { BaseLanguageModel } from '@langchain/core/language_models/base';
3
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
+ import { ICopilotModel, ILLMUsage } from '@metad/contracts';
5
+ import { Command } from '@nestjs/cqrs';
6
+ import { IRerank } from '../types';
7
+ /**
8
+ * Get a Chat Model of copilot model and check it's token limitation, record the token usage
9
+ */
10
+ export declare class CreateModelClientCommand<T = BaseLanguageModel | BaseChatModel | Embeddings | IRerank> extends Command<T> {
11
+ readonly copilotModel: ICopilotModel;
12
+ readonly options: {
13
+ abortController?: AbortController;
14
+ usageCallback: (tokens: ILLMUsage) => void;
15
+ };
16
+ static readonly type = "[AI Model] Create Model Client";
17
+ constructor(copilotModel: ICopilotModel, options: {
18
+ abortController?: AbortController;
19
+ usageCallback: (tokens: ILLMUsage) => void;
20
+ });
21
+ }
@@ -0,0 +1 @@
1
+ export * from './create-model-client.command';
@@ -7,3 +7,4 @@ export * from './llm';
7
7
  export * from './errors';
8
8
  export * from './openai-compatible';
9
9
  export * from './utils/index';
10
+ export * from './commands/index';
@@ -3,6 +3,7 @@ export * from './rerank';
3
3
  export * from './model';
4
4
  export * from './speech2text';
5
5
  export * from './tts';
6
+ export * from './profile';
6
7
  export declare const PROVIDE_AI_MODEL_LLM = "provide_ai_model_llm";
7
8
  export declare const PROVIDE_AI_MODEL_MODERATION = "provide_ai_model_moderation";
8
9
  export declare const PROVIDE_AI_MODEL_SPEECH2TEXT = "provide_ai_model_speech2text";
@@ -1,5 +1,5 @@
1
1
  import { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
- import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ParameterType } from "@metad/contracts";
2
+ import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ParameterType, PriceInfo, PriceType } from "@metad/contracts";
3
3
  export type TChatModelOptions = {
4
4
  modelProperties: Record<string, any>;
5
5
  handleLLMTokens: (input: {
@@ -17,6 +17,7 @@ export interface IAIModel {
17
17
  validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
18
18
  getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
19
19
  predefinedModels(): AIModelEntity[];
20
+ getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number): PriceInfo;
20
21
  }
21
22
  export declare const CommonParameterRules: {
22
23
  name: string;
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @deprecated Migrate to langchain v1
3
+ *
4
+ * Represents the capabilities and constraints of a language model.
5
+ *
6
+ * This interface defines the various features and limitations that a model may have,
7
+ * including input/output constraints, multimodal support, and advanced capabilities
8
+ * like tool calling and structured output.
9
+ */
10
+ export interface ModelProfile {
11
+ /**
12
+ * Maximum number of tokens that can be included in the input context window.
13
+ *
14
+ * This represents the total token budget for the model's input, including
15
+ * the prompt, system messages, conversation history, and any other context.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const profile: ModelProfile = {
20
+ * maxInputTokens: 128000 // Model supports up to 128k tokens
21
+ * };
22
+ * ```
23
+ */
24
+ maxInputTokens?: number;
25
+ /**
26
+ * Whether the model supports image inputs.
27
+ *
28
+ * When `true`, the model can process images as part of its input, enabling
29
+ * multimodal interactions where visual content can be analyzed alongside text.
30
+ *
31
+ * @see {@link imageUrlInputs} for URL-based image input support
32
+ */
33
+ imageInputs?: boolean;
34
+ /**
35
+ * Whether the model supports image URL inputs.
36
+ *
37
+ * When `true`, the model can accept URLs pointing to images rather than
38
+ * requiring the image data to be embedded directly in the request. This can
39
+ * be more efficient for large images or when images are already hosted.
40
+ *
41
+ * @see {@link imageInputs} for direct image input support
42
+ */
43
+ imageUrlInputs?: boolean;
44
+ /**
45
+ * Whether the model supports PDF document inputs.
46
+ *
47
+ * When `true`, the model can process PDF files as input, allowing it to
48
+ * analyze document content, extract information, or answer questions about
49
+ * PDF documents.
50
+ */
51
+ pdfInputs?: boolean;
52
+ /**
53
+ * Whether the model supports audio inputs.
54
+ *
55
+ * When `true`, the model can process audio data as input, enabling
56
+ * capabilities like speech recognition, audio analysis, or multimodal
57
+ * interactions involving sound.
58
+ */
59
+ audioInputs?: boolean;
60
+ /**
61
+ * Whether the model supports video inputs.
62
+ *
63
+ * When `true`, the model can process video data as input, enabling
64
+ * capabilities like video analysis, scene understanding, or multimodal
65
+ * interactions involving moving images.
66
+ */
67
+ videoInputs?: boolean;
68
+ /**
69
+ * Whether the model supports image content in tool messages.
70
+ *
71
+ * When `true`, tool responses can include images that the model can process
72
+ * and reason about. This enables workflows where tools return visual data
73
+ * that the model needs to interpret.
74
+ */
75
+ imageToolMessage?: boolean;
76
+ /**
77
+ * Whether the model supports PDF content in tool messages.
78
+ *
79
+ * When `true`, tool responses can include PDF documents that the model can
80
+ * process and reason about. This enables workflows where tools return
81
+ * document data that the model needs to interpret.
82
+ */
83
+ pdfToolMessage?: boolean;
84
+ /**
85
+ * Maximum number of tokens the model can generate in its output.
86
+ *
87
+ * This represents the upper limit on the length of the model's response.
88
+ * The actual output may be shorter depending on the completion criteria
89
+ * (e.g., natural stopping point, stop sequences).
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const profile: ModelProfile = {
94
+ * maxOutputTokens: 4096 // Model can generate up to 4k tokens
95
+ * };
96
+ * ```
97
+ */
98
+ maxOutputTokens?: number;
99
+ /**
100
+ * Whether the model supports reasoning or chain-of-thought output.
101
+ *
102
+ * When `true`, the model can produce explicit reasoning steps or
103
+ * chain-of-thought explanations as part of its output. This is useful
104
+ * for understanding the model's decision-making process and improving
105
+ * transparency in complex reasoning tasks.
106
+ */
107
+ reasoningOutput?: boolean;
108
+ /**
109
+ * Whether the model can generate image outputs.
110
+ *
111
+ * When `true`, the model can produce images as part of its response,
112
+ * enabling capabilities like image generation, editing, or visual
113
+ * content creation.
114
+ */
115
+ imageOutputs?: boolean;
116
+ /**
117
+ * Whether the model can generate audio outputs.
118
+ *
119
+ * When `true`, the model can produce audio data as part of its response,
120
+ * enabling capabilities like text-to-speech, audio generation, or
121
+ * sound synthesis.
122
+ */
123
+ audioOutputs?: boolean;
124
+ /**
125
+ * Whether the model can generate video outputs.
126
+ *
127
+ * When `true`, the model can produce video data as part of its response,
128
+ * enabling capabilities like video generation, editing, or visual
129
+ * content creation with motion.
130
+ */
131
+ videoOutputs?: boolean;
132
+ /**
133
+ * Whether the model supports tool calling (function calling).
134
+ *
135
+ * When `true`, the model can invoke external tools or functions during
136
+ * its reasoning process. The model can decide which tools to call,
137
+ * with what arguments, and can incorporate the tool results into its
138
+ * final response.
139
+ *
140
+ * @see {@link toolChoice} for controlling tool selection behavior
141
+ * @see {@link https://docs.langchain.com/oss/javascript/langchain/models#tool-calling}
142
+ */
143
+ toolCalling?: boolean;
144
+ /**
145
+ * Whether the model supports tool choice control.
146
+ *
147
+ * When `true`, the caller can specify how the model should select tools,
148
+ * such as forcing the use of a specific tool, allowing any tool, or
149
+ * preventing tool use entirely. This provides fine-grained control over
150
+ * the model's tool-calling behavior.
151
+ *
152
+ * @see {@link toolCalling} for basic tool calling support
153
+ */
154
+ toolChoice?: boolean;
155
+ /**
156
+ * Whether the model supports structured output generation.
157
+ *
158
+ * When `true`, the model can generate responses that conform to a
159
+ * specified schema or structure (e.g., JSON with a particular format).
160
+ * This is useful for ensuring the model's output can be reliably parsed
161
+ * and processed programmatically.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * // Model can be instructed to return JSON matching a schema
166
+ * const profile: ModelProfile = {
167
+ * structuredOutput: true
168
+ * };
169
+ * ```
170
+ */
171
+ structuredOutput?: boolean;
172
+ }
@@ -4,3 +4,5 @@ export * from './schema';
4
4
  export * from './i18n';
5
5
  export * from './utils';
6
6
  export * from './context/index';
7
+ export * from './types';
8
+ export * from './strategy-bus';
@@ -0,0 +1,17 @@
1
+ import { StrategyEntry } from './types';
2
+ export type StrategyBusEvent<S = any> = {
3
+ type: 'UPSERT';
4
+ strategyType: string;
5
+ entry: StrategyEntry<S>;
6
+ } | {
7
+ type: 'REMOVE';
8
+ strategyType?: string;
9
+ pluginName: string;
10
+ orgId: string;
11
+ };
12
+ export declare class StrategyBus {
13
+ private readonly subject;
14
+ readonly events$: import("rxjs").Observable<StrategyBusEvent<any>>;
15
+ upsert<S>(strategyType: string, entry: StrategyEntry<S>): void;
16
+ remove(orgId: string, pluginName: string): void;
17
+ }