@xpert-ai/plugin-sdk 3.7.1 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +78 -834
- package/index.esm.js +77 -834
- package/package.json +4 -1
- package/src/lib/agent/middleware/types.d.ts +72 -7
- package/src/lib/ai-model/ai-model.d.ts +3 -1
- package/src/lib/core/utils.d.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
"@nestjs/common": "*",
|
|
24
24
|
"@nestjs/core": "*",
|
|
25
25
|
"@nestjs/cqrs": "*",
|
|
26
|
+
"ajv": "*",
|
|
26
27
|
"lodash-es": "*",
|
|
27
28
|
"i18next-fs-backend": "*",
|
|
28
29
|
"i18next": "*",
|
|
30
|
+
"json-schema": "*",
|
|
29
31
|
"jsonwebtoken": "*",
|
|
30
32
|
"fs": "*",
|
|
31
33
|
"path": "*",
|
|
32
34
|
"passport-jwt": "*",
|
|
35
|
+
"rxjs": "*",
|
|
33
36
|
"stream": "*",
|
|
34
37
|
"yaml": "*",
|
|
35
38
|
"zod": "*"
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { LanguageModelLike } from '@langchain/core/language_models/base';
|
|
2
2
|
import { AIMessage, BaseMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
-
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { DynamicStructuredTool, DynamicTool, StructuredToolInterface } from '@langchain/core/tools';
|
|
4
|
+
import type { ToolCall, ToolMessage } from "@langchain/core/messages/tool";
|
|
5
|
+
import { InferInteropZodOutput, InteropZodObject } from '@langchain/core/utils/types';
|
|
6
|
+
import { RunnableToolLike } from '@langchain/core/runnables';
|
|
7
|
+
import { AgentBuiltInState, Runtime } from './runtime';
|
|
8
|
+
import { Command } from '@langchain/langgraph';
|
|
9
|
+
export type ServerTool = Record<string, unknown>;
|
|
10
|
+
export type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
|
|
11
|
+
export type NormalizedSchemaInput<TSchema extends InteropZodObject | undefined | never = any> = [TSchema] extends [never] ? AgentBuiltInState : TSchema extends InteropZodObject ? InferInteropZodOutput<TSchema> & AgentBuiltInState : TSchema extends Record<string, unknown> ? TSchema & AgentBuiltInState : AgentBuiltInState;
|
|
12
|
+
type NormalizeContextSchema<TContextSchema extends InteropZodObject | undefined = undefined> = TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : never;
|
|
6
13
|
/**
|
|
7
14
|
* jump targets (user facing)
|
|
8
15
|
*/
|
|
@@ -95,7 +102,7 @@ export type AfterAgentHook<TSchema extends InteropZodObject | undefined = undefi
|
|
|
95
102
|
* @template TState - The agent's state type, must extend Record<string, unknown>. Defaults to Record<string, unknown>.
|
|
96
103
|
* @template TContext - The runtime context type for accessing metadata and control flow. Defaults to unknown.
|
|
97
104
|
*/
|
|
98
|
-
export interface ModelRequest<TState =
|
|
105
|
+
export interface ModelRequest<TState extends Record<string, unknown> = Record<string, unknown>, TContext = unknown> {
|
|
99
106
|
/**
|
|
100
107
|
* The model to use for this step.
|
|
101
108
|
*/
|
|
@@ -105,6 +112,31 @@ export interface ModelRequest<TState = any, TContext = unknown> {
|
|
|
105
112
|
*/
|
|
106
113
|
messages: BaseMessage[];
|
|
107
114
|
systemMessage?: SystemMessage;
|
|
115
|
+
/**
|
|
116
|
+
* Tool choice configuration (model-specific format).
|
|
117
|
+
* Can be one of:
|
|
118
|
+
* - `"auto"`: means the model can pick between generating a message or calling one or more tools.
|
|
119
|
+
* - `"none"`: means the model will not call any tool and instead generates a message.
|
|
120
|
+
* - `"required"`: means the model must call one or more tools.
|
|
121
|
+
* - `{ type: "function", function: { name: string } }`: The model will use the specified function.
|
|
122
|
+
*/
|
|
123
|
+
toolChoice?: "auto" | "none" | "required" | {
|
|
124
|
+
type: "function";
|
|
125
|
+
function: {
|
|
126
|
+
name: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* The tools to make available for this step.
|
|
131
|
+
*/
|
|
132
|
+
tools: (ServerTool | ClientTool)[];
|
|
133
|
+
/**
|
|
134
|
+
* The current agent state (includes both middleware state and built-in state).
|
|
135
|
+
*/
|
|
136
|
+
state: TState & AgentBuiltInState;
|
|
137
|
+
/**
|
|
138
|
+
* The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
139
|
+
*/
|
|
108
140
|
runtime: Runtime<TContext>;
|
|
109
141
|
}
|
|
110
142
|
/**
|
|
@@ -114,7 +146,7 @@ export interface ModelRequest<TState = any, TContext = unknown> {
|
|
|
114
146
|
* @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime
|
|
115
147
|
* @returns The AI message response from the model
|
|
116
148
|
*/
|
|
117
|
-
export type WrapModelCallHandler<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema
|
|
149
|
+
export type WrapModelCallHandler<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<AIMessage>;
|
|
118
150
|
/**
|
|
119
151
|
* Wrapper function type for the wrapModelCall hook.
|
|
120
152
|
* Allows middleware to intercept and modify model execution.
|
|
@@ -128,7 +160,40 @@ export type WrapModelCallHandler<TSchema extends InteropZodObject | undefined =
|
|
|
128
160
|
* @param handler - The function that invokes the model. Call this with a ModelRequest to get the response
|
|
129
161
|
* @returns The AI message response from the model (or a modified version)
|
|
130
162
|
*/
|
|
131
|
-
export type WrapModelCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema
|
|
163
|
+
export type WrapModelCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: WrapModelCallHandler<TSchema, TContext>) => PromiseOrValue<AIMessage>;
|
|
164
|
+
/**
|
|
165
|
+
* Represents a tool call request for the wrapToolCall hook.
|
|
166
|
+
* Contains the tool call information along with the agent's current state and runtime.
|
|
167
|
+
*/
|
|
168
|
+
export interface ToolCallRequest<TState extends Record<string, unknown> = Record<string, unknown>, TContext = unknown> {
|
|
169
|
+
/**
|
|
170
|
+
* The tool call to be executed
|
|
171
|
+
*/
|
|
172
|
+
toolCall: ToolCall;
|
|
173
|
+
/**
|
|
174
|
+
* The BaseTool instance being invoked.
|
|
175
|
+
* Provides access to tool metadata like name, description, schema, etc.
|
|
176
|
+
*/
|
|
177
|
+
tool: ClientTool | ServerTool;
|
|
178
|
+
/**
|
|
179
|
+
* The current agent state (includes both middleware state and built-in state).
|
|
180
|
+
*/
|
|
181
|
+
state: TState & AgentBuiltInState;
|
|
182
|
+
/**
|
|
183
|
+
* The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
184
|
+
*/
|
|
185
|
+
runtime: Runtime<TContext>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Handler function type for wrapping tool calls.
|
|
189
|
+
* Takes a tool call request and returns the tool result or a command.
|
|
190
|
+
*/
|
|
191
|
+
export type ToolCallHandler<TSchema extends Record<string, unknown> = AgentBuiltInState, TContext = unknown> = (request: ToolCallRequest<TSchema, TContext>) => PromiseOrValue<ToolMessage | Command>;
|
|
192
|
+
/**
|
|
193
|
+
* Wrapper function type for the wrapToolCall hook.
|
|
194
|
+
* Allows middleware to intercept and modify tool execution.
|
|
195
|
+
*/
|
|
196
|
+
export type WrapToolCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ToolCallRequest<NormalizedSchemaInput<TSchema>, TContext>, handler: ToolCallHandler<NormalizedSchemaInput<TSchema>, TContext>) => PromiseOrValue<ToolMessage | Command>;
|
|
132
197
|
export interface AgentMiddleware<TSchema extends InteropZodObject | undefined = any, TContextSchema extends InteropZodObject | undefined = any, TFullContext = any> {
|
|
133
198
|
/**
|
|
134
199
|
* The name of the middleware.
|
|
@@ -246,6 +311,6 @@ export interface AgentMiddleware<TSchema extends InteropZodObject | undefined =
|
|
|
246
311
|
* }
|
|
247
312
|
* ```
|
|
248
313
|
*/
|
|
249
|
-
wrapToolCall?:
|
|
314
|
+
wrapToolCall?: WrapToolCallHook<TSchema, NormalizeContextSchema<TContextSchema>>;
|
|
250
315
|
}
|
|
251
316
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
2
|
import { AIModelEntity, AiModelTypeEnum, ICopilotModel, ParameterRule, PriceInfo, PriceType } from '@metad/contracts';
|
|
3
3
|
import { Logger } from '@nestjs/common';
|
|
4
|
-
import { IAIModel, TChatModelOptions } from './types/';
|
|
5
4
|
import { ModelProvider } from './abstract-provider';
|
|
5
|
+
import { IAIModel, TChatModelOptions } from './types/model';
|
|
6
|
+
import { ModelProfile } from './types/profile';
|
|
6
7
|
export declare abstract class AIModel implements IAIModel {
|
|
7
8
|
protected readonly modelProvider: ModelProvider;
|
|
8
9
|
modelType: AiModelTypeEnum;
|
|
@@ -30,4 +31,5 @@ export declare abstract class AIModel implements IAIModel {
|
|
|
30
31
|
private sortModelSchemas;
|
|
31
32
|
protected _commonParameterRules(model: string): ParameterRule[];
|
|
32
33
|
getParameterRules(model: string, credentials: Record<string, string>): ParameterRule[];
|
|
34
|
+
getModelProfile(model: string, credentials: unknown): ModelProfile;
|
|
33
35
|
}
|
package/src/lib/core/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { JSONSchema4 } from 'json-schema';
|
|
2
3
|
export declare function loadYamlFile<T>(filePath: string, logger?: Logger, ignoreError?: boolean, defaultValue?: T): T;
|
|
3
4
|
/**
|
|
4
5
|
* Get the mapping from name to index from a YAML file
|
|
@@ -10,3 +11,8 @@ export declare function loadYamlFile<T>(filePath: string, logger?: Logger, ignor
|
|
|
10
11
|
export declare function getPositionMap(folderPath: string, fileName?: string, logger?: Logger): Record<string, number>;
|
|
11
12
|
export declare function getPositionList(folderPath: string, fileName?: string, logger?: Logger): string[];
|
|
12
13
|
export declare function getErrorMessage(err: any): string;
|
|
14
|
+
export declare class JsonSchemaValidator {
|
|
15
|
+
private ajv;
|
|
16
|
+
constructor();
|
|
17
|
+
parseAndValidate(schemaStr?: string): JSONSchema4 | undefined;
|
|
18
|
+
}
|