@xpert-ai/plugin-sdk 3.6.7 → 3.7.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/SCHEMA_SPECIFICATION.md +2 -1
- package/index.cjs.js +140 -0
- package/index.esm.js +136 -1
- package/package.json +2 -1
- package/src/index.d.ts +1 -0
- package/src/lib/agent/index.d.ts +1 -0
- package/src/lib/agent/middleware/index.d.ts +4 -0
- package/src/lib/agent/middleware/strategy.decorator.d.ts +2 -0
- package/src/lib/agent/middleware/strategy.interface.d.ts +16 -0
- package/src/lib/agent/middleware/strategy.registry.d.ts +6 -0
- package/src/lib/agent/middleware/types.d.ts +249 -0
- package/src/lib/agent/skill/index.d.ts +3 -0
- package/src/lib/agent/skill/skill-source-provider.decorator.d.ts +2 -0
- package/src/lib/agent/skill/skill-source-provider.interface.d.ts +23 -0
- package/src/lib/agent/skill/skill-source-provider.registry.d.ts +6 -0
- package/src/lib/ai-model/commands/create-model-client.command.d.ts +21 -0
- package/src/lib/ai-model/commands/index.d.ts +1 -0
- package/src/lib/ai-model/index.d.ts +1 -0
- package/src/lib/ai-model/types/index.d.ts +1 -0
- package/src/lib/ai-model/types/model.d.ts +2 -1
- package/src/lib/ai-model/types/profile.d.ts +172 -0
- package/src/lib/data/datasource/types.d.ts +29 -1
- package/src/lib/workflow/commands/index.d.ts +1 -0
- package/src/lib/workflow/commands/wrap-workflow-node-execution.command.d.ts +26 -0
- package/src/lib/workflow/index.d.ts +1 -0
package/SCHEMA_SPECIFICATION.md
CHANGED
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
| 字段名 | 类型 | 说明 |
|
|
24
24
|
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------------ |
|
|
25
|
-
| `component` | string | 指定 UI 组件类型,如 `textInput`, `textarea`, `select`, `switch`, `slider`, `
|
|
25
|
+
| `component` | string | 指定 UI 组件类型,如 `textInput`, `textarea`, `select`, `switch`, `slider`, `prompt-editor`, `ai-model-select` |
|
|
26
|
+
| `inputs` | object | 自定义组件的额外输入属性值 |
|
|
26
27
|
| `label` | string | UI 展示的标签 |
|
|
27
28
|
| `description` | string | UI 展示的帮助文本,优先覆盖 schema.description |
|
|
28
29
|
| `help` | string | 额外提示信息,如 tooltip,前端会按需展示小问号或工具提示 |
|
package/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ var common = require('@nestjs/common');
|
|
|
4
4
|
var constants = require('@nestjs/common/constants');
|
|
5
5
|
var lodashEs = require('lodash-es');
|
|
6
6
|
var core = require('@nestjs/core');
|
|
7
|
+
var cqrs = require('@nestjs/cqrs');
|
|
7
8
|
var fs = require('fs');
|
|
8
9
|
var http = require('http');
|
|
9
10
|
var https = require('https');
|
|
@@ -210,6 +211,17 @@ exports.WorkflowNodeRegistry = __decorate([
|
|
|
210
211
|
])
|
|
211
212
|
], exports.WorkflowNodeRegistry);
|
|
212
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Wrap Workflow Node Execution Command
|
|
216
|
+
*/ class WrapWorkflowNodeExecutionCommand extends cqrs.Command {
|
|
217
|
+
constructor(fuc, params){
|
|
218
|
+
super();
|
|
219
|
+
this.fuc = fuc;
|
|
220
|
+
this.params = params;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
WrapWorkflowNodeExecutionCommand.type = '[Workflow] Wrap Workflow Node Execution';
|
|
224
|
+
|
|
213
225
|
const VECTOR_STORE_STRATEGY = 'VECTOR_STORE_STRATEGY';
|
|
214
226
|
const VectorStoreStrategy = (provider)=>common.SetMetadata(VECTOR_STORE_STRATEGY, provider);
|
|
215
227
|
|
|
@@ -1080,6 +1092,93 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1080
1092
|
async ping() {
|
|
1081
1093
|
await this.runQuery(`SELECT 1`);
|
|
1082
1094
|
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Default implementation for table operations
|
|
1097
|
+
*/ async tableOp(action, params, options) {
|
|
1098
|
+
switch(action){
|
|
1099
|
+
case "createTable":
|
|
1100
|
+
{
|
|
1101
|
+
// Default implementation for creating table (generic SQL syntax)
|
|
1102
|
+
const { schema, table, columns, createMode = "error" } = params;
|
|
1103
|
+
const tableName = schema ? `${schema}.${table}` : table;
|
|
1104
|
+
// Check if table exists (try to query table info)
|
|
1105
|
+
let exists = false;
|
|
1106
|
+
try {
|
|
1107
|
+
const result = await this.runQuery(`SELECT * FROM ${tableName} WHERE 1=0`, options);
|
|
1108
|
+
exists = true;
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
// Table does not exist
|
|
1111
|
+
exists = false;
|
|
1112
|
+
}
|
|
1113
|
+
// --- MODE: ERROR → throw error if table exists ---
|
|
1114
|
+
if (exists && createMode === "error") {
|
|
1115
|
+
throw new Error(`Table "${tableName}" already exists`);
|
|
1116
|
+
}
|
|
1117
|
+
// --- MODE: IGNORE → do nothing if exists ---
|
|
1118
|
+
if (exists && createMode === "ignore") {
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
// --- MODE: UPGRADE → auto upgrade (simple implementation: only add new columns) ---
|
|
1122
|
+
// Note: This default implementation does not support modifying column types,
|
|
1123
|
+
// recommend each database to implement its own version
|
|
1124
|
+
if (exists && createMode === "upgrade") {
|
|
1125
|
+
console.warn(`[BaseSQLQueryRunner] UPGRADE mode uses basic implementation. Consider implementing tableOp for better support.`);
|
|
1126
|
+
// Try to add new columns (will fail if column already exists, but doesn't affect)
|
|
1127
|
+
for (const col of columns){
|
|
1128
|
+
try {
|
|
1129
|
+
const colType = this.mapColumnType(col.type, col.isKey, col.length);
|
|
1130
|
+
await this.runQuery(`ALTER TABLE ${tableName} ADD COLUMN ${col.fieldName} ${colType}`, options);
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
// Field might already exist, ignore error
|
|
1133
|
+
console.debug(`Failed to add column ${col.fieldName}:`, error instanceof Error ? error.message : String(error));
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
// --- MODE: CREATE NEW TABLE ---
|
|
1139
|
+
const columnsDDL = columns.map((col)=>{
|
|
1140
|
+
const colType = this.mapColumnType(col.type, col.isKey, col.length);
|
|
1141
|
+
const pk = col.isKey ? ' PRIMARY KEY' : '';
|
|
1142
|
+
const notNull = col.required ? ' NOT NULL' : '';
|
|
1143
|
+
return `${col.fieldName} ${colType}${pk}${notNull}`;
|
|
1144
|
+
}).join(', ');
|
|
1145
|
+
const createTableStatement = `CREATE TABLE ${tableName} (${columnsDDL})`;
|
|
1146
|
+
await this.runQuery(createTableStatement, options);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
case "dropTable":
|
|
1150
|
+
{
|
|
1151
|
+
// Default implementation for dropping table
|
|
1152
|
+
const { schema, table } = params;
|
|
1153
|
+
const tableName = schema ? `${schema}.${table}` : table;
|
|
1154
|
+
await this.runQuery(`DROP TABLE IF EXISTS ${tableName}`, options);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
default:
|
|
1158
|
+
// Throw error for other unimplemented operations
|
|
1159
|
+
throw new Error(`Unsupported table action: ${action}`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Generic type mapping (subclasses can override)
|
|
1164
|
+
*/ mapColumnType(type, isKey, length) {
|
|
1165
|
+
switch(type == null ? void 0 : type.toLowerCase()){
|
|
1166
|
+
case 'string':
|
|
1167
|
+
return length ? `VARCHAR(${length})` : isKey ? 'VARCHAR(255)' : 'VARCHAR(1000)';
|
|
1168
|
+
case 'number':
|
|
1169
|
+
return 'INT';
|
|
1170
|
+
case 'boolean':
|
|
1171
|
+
return 'BOOLEAN';
|
|
1172
|
+
case 'date':
|
|
1173
|
+
return 'DATE';
|
|
1174
|
+
case 'datetime':
|
|
1175
|
+
return 'TIMESTAMP';
|
|
1176
|
+
case 'object':
|
|
1177
|
+
return 'TEXT';
|
|
1178
|
+
default:
|
|
1179
|
+
return 'VARCHAR(1000)';
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1083
1182
|
constructor(...args){
|
|
1084
1183
|
super(...args);
|
|
1085
1184
|
this.syntax = "sql";
|
|
@@ -2049,6 +2148,42 @@ class Speech2TextChatModel extends chat_models.BaseChatModel {
|
|
|
2049
2148
|
return 0;
|
|
2050
2149
|
}
|
|
2051
2150
|
|
|
2151
|
+
/**
|
|
2152
|
+
* Get a Chat Model of copilot model and check it's token limitation, record the token usage
|
|
2153
|
+
*/ class CreateModelClientCommand extends cqrs.Command {
|
|
2154
|
+
constructor(copilotModel, options){
|
|
2155
|
+
super();
|
|
2156
|
+
this.copilotModel = copilotModel;
|
|
2157
|
+
this.options = options;
|
|
2158
|
+
}
|
|
2159
|
+
}
|
|
2160
|
+
CreateModelClientCommand.type = '[AI Model] Create Model Client';
|
|
2161
|
+
|
|
2162
|
+
const AGENT_MIDDLEWARE_STRATEGY = 'AGENT_MIDDLEWARE_STRATEGY';
|
|
2163
|
+
const AgentMiddlewareStrategy = (provider)=>common.SetMetadata(AGENT_MIDDLEWARE_STRATEGY, provider);
|
|
2164
|
+
|
|
2165
|
+
exports.AgentMiddlewareRegistry = class AgentMiddlewareRegistry extends BaseStrategyRegistry {
|
|
2166
|
+
constructor(discoveryService, reflector){
|
|
2167
|
+
super(AGENT_MIDDLEWARE_STRATEGY, discoveryService, reflector);
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
exports.AgentMiddlewareRegistry = __decorate([
|
|
2171
|
+
common.Injectable(),
|
|
2172
|
+
__metadata("design:type", Function),
|
|
2173
|
+
__metadata("design:paramtypes", [
|
|
2174
|
+
typeof core.DiscoveryService === "undefined" ? Object : core.DiscoveryService,
|
|
2175
|
+
typeof core.Reflector === "undefined" ? Object : core.Reflector
|
|
2176
|
+
])
|
|
2177
|
+
], exports.AgentMiddlewareRegistry);
|
|
2178
|
+
|
|
2179
|
+
/**
|
|
2180
|
+
* jump targets (user facing)
|
|
2181
|
+
*/ const JUMP_TO_TARGETS = [
|
|
2182
|
+
"model",
|
|
2183
|
+
"tools",
|
|
2184
|
+
"end"
|
|
2185
|
+
];
|
|
2186
|
+
|
|
2052
2187
|
Object.defineProperty(exports, "IColumnDef", {
|
|
2053
2188
|
enumerable: true,
|
|
2054
2189
|
get: function () { return contracts.IColumnDef; }
|
|
@@ -2065,10 +2200,12 @@ Object.defineProperty(exports, "TDocumentAsset", {
|
|
|
2065
2200
|
enumerable: true,
|
|
2066
2201
|
get: function () { return contracts.TDocumentAsset; }
|
|
2067
2202
|
});
|
|
2203
|
+
exports.AGENT_MIDDLEWARE_STRATEGY = AGENT_MIDDLEWARE_STRATEGY;
|
|
2068
2204
|
exports.AIModelProviderNotFoundException = AIModelProviderNotFoundException;
|
|
2069
2205
|
exports.AIModelProviderStrategy = AIModelProviderStrategy;
|
|
2070
2206
|
exports.AI_MODEL_PROVIDER = AI_MODEL_PROVIDER;
|
|
2071
2207
|
exports.AdapterDataSourceStrategy = AdapterDataSourceStrategy;
|
|
2208
|
+
exports.AgentMiddlewareStrategy = AgentMiddlewareStrategy;
|
|
2072
2209
|
exports.AiModelNotFoundException = AiModelNotFoundException;
|
|
2073
2210
|
exports.BaseHTTPQueryRunner = BaseHTTPQueryRunner;
|
|
2074
2211
|
exports.BaseQueryRunner = BaseQueryRunner;
|
|
@@ -2078,6 +2215,7 @@ exports.BaseToolset = BaseToolset;
|
|
|
2078
2215
|
exports.BuiltinToolset = BuiltinToolset;
|
|
2079
2216
|
exports.ChatOAICompatReasoningModel = ChatOAICompatReasoningModel;
|
|
2080
2217
|
exports.CommonParameterRules = CommonParameterRules;
|
|
2218
|
+
exports.CreateModelClientCommand = CreateModelClientCommand;
|
|
2081
2219
|
exports.CredentialsValidateFailedError = CredentialsValidateFailedError;
|
|
2082
2220
|
exports.DATASOURCE_STRATEGY = DATASOURCE_STRATEGY;
|
|
2083
2221
|
exports.DOCUMENT_SOURCE_STRATEGY = DOCUMENT_SOURCE_STRATEGY;
|
|
@@ -2089,6 +2227,7 @@ exports.IMAGE_UNDERSTANDING_STRATEGY = IMAGE_UNDERSTANDING_STRATEGY;
|
|
|
2089
2227
|
exports.INTEGRATION_STRATEGY = INTEGRATION_STRATEGY;
|
|
2090
2228
|
exports.ImageUnderstandingStrategy = ImageUnderstandingStrategy;
|
|
2091
2229
|
exports.IntegrationStrategyKey = IntegrationStrategyKey;
|
|
2230
|
+
exports.JUMP_TO_TARGETS = JUMP_TO_TARGETS;
|
|
2092
2231
|
exports.KNOWLEDGE_STRATEGY = KNOWLEDGE_STRATEGY;
|
|
2093
2232
|
exports.KnowledgeStrategyKey = KnowledgeStrategyKey;
|
|
2094
2233
|
exports.LLMUsage = LLMUsage;
|
|
@@ -2119,6 +2258,7 @@ exports.WORKFLOW_NODE_STRATEGY = WORKFLOW_NODE_STRATEGY;
|
|
|
2119
2258
|
exports.WORKFLOW_TRIGGER_STRATEGY = WORKFLOW_TRIGGER_STRATEGY;
|
|
2120
2259
|
exports.WorkflowNodeStrategy = WorkflowNodeStrategy;
|
|
2121
2260
|
exports.WorkflowTriggerStrategy = WorkflowTriggerStrategy;
|
|
2261
|
+
exports.WrapWorkflowNodeExecutionCommand = WrapWorkflowNodeExecutionCommand;
|
|
2122
2262
|
exports.XpFileSystem = XpFileSystem;
|
|
2123
2263
|
exports.XpertServerPlugin = XpertServerPlugin;
|
|
2124
2264
|
exports.als = als;
|
package/index.esm.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Module, Logger, SetMetadata, Injectable, HttpException, HttpStatus, Not
|
|
|
2
2
|
import { MODULE_METADATA } from '@nestjs/common/constants';
|
|
3
3
|
import { pick } from 'lodash-es';
|
|
4
4
|
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
5
|
+
import { Command } from '@nestjs/cqrs';
|
|
5
6
|
import * as fs from 'fs';
|
|
6
7
|
import fs__default from 'fs';
|
|
7
8
|
import http from 'http';
|
|
@@ -190,6 +191,17 @@ WorkflowNodeRegistry = __decorate([
|
|
|
190
191
|
])
|
|
191
192
|
], WorkflowNodeRegistry);
|
|
192
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Wrap Workflow Node Execution Command
|
|
196
|
+
*/ class WrapWorkflowNodeExecutionCommand extends Command {
|
|
197
|
+
constructor(fuc, params){
|
|
198
|
+
super();
|
|
199
|
+
this.fuc = fuc;
|
|
200
|
+
this.params = params;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
WrapWorkflowNodeExecutionCommand.type = '[Workflow] Wrap Workflow Node Execution';
|
|
204
|
+
|
|
193
205
|
const VECTOR_STORE_STRATEGY = 'VECTOR_STORE_STRATEGY';
|
|
194
206
|
const VectorStoreStrategy = (provider)=>SetMetadata(VECTOR_STORE_STRATEGY, provider);
|
|
195
207
|
|
|
@@ -1060,6 +1072,93 @@ class BaseSQLQueryRunner extends BaseQueryRunner {
|
|
|
1060
1072
|
async ping() {
|
|
1061
1073
|
await this.runQuery(`SELECT 1`);
|
|
1062
1074
|
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Default implementation for table operations
|
|
1077
|
+
*/ async tableOp(action, params, options) {
|
|
1078
|
+
switch(action){
|
|
1079
|
+
case "createTable":
|
|
1080
|
+
{
|
|
1081
|
+
// Default implementation for creating table (generic SQL syntax)
|
|
1082
|
+
const { schema, table, columns, createMode = "error" } = params;
|
|
1083
|
+
const tableName = schema ? `${schema}.${table}` : table;
|
|
1084
|
+
// Check if table exists (try to query table info)
|
|
1085
|
+
let exists = false;
|
|
1086
|
+
try {
|
|
1087
|
+
const result = await this.runQuery(`SELECT * FROM ${tableName} WHERE 1=0`, options);
|
|
1088
|
+
exists = true;
|
|
1089
|
+
} catch (error) {
|
|
1090
|
+
// Table does not exist
|
|
1091
|
+
exists = false;
|
|
1092
|
+
}
|
|
1093
|
+
// --- MODE: ERROR → throw error if table exists ---
|
|
1094
|
+
if (exists && createMode === "error") {
|
|
1095
|
+
throw new Error(`Table "${tableName}" already exists`);
|
|
1096
|
+
}
|
|
1097
|
+
// --- MODE: IGNORE → do nothing if exists ---
|
|
1098
|
+
if (exists && createMode === "ignore") {
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
// --- MODE: UPGRADE → auto upgrade (simple implementation: only add new columns) ---
|
|
1102
|
+
// Note: This default implementation does not support modifying column types,
|
|
1103
|
+
// recommend each database to implement its own version
|
|
1104
|
+
if (exists && createMode === "upgrade") {
|
|
1105
|
+
console.warn(`[BaseSQLQueryRunner] UPGRADE mode uses basic implementation. Consider implementing tableOp for better support.`);
|
|
1106
|
+
// Try to add new columns (will fail if column already exists, but doesn't affect)
|
|
1107
|
+
for (const col of columns){
|
|
1108
|
+
try {
|
|
1109
|
+
const colType = this.mapColumnType(col.type, col.isKey, col.length);
|
|
1110
|
+
await this.runQuery(`ALTER TABLE ${tableName} ADD COLUMN ${col.fieldName} ${colType}`, options);
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
// Field might already exist, ignore error
|
|
1113
|
+
console.debug(`Failed to add column ${col.fieldName}:`, error instanceof Error ? error.message : String(error));
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
// --- MODE: CREATE NEW TABLE ---
|
|
1119
|
+
const columnsDDL = columns.map((col)=>{
|
|
1120
|
+
const colType = this.mapColumnType(col.type, col.isKey, col.length);
|
|
1121
|
+
const pk = col.isKey ? ' PRIMARY KEY' : '';
|
|
1122
|
+
const notNull = col.required ? ' NOT NULL' : '';
|
|
1123
|
+
return `${col.fieldName} ${colType}${pk}${notNull}`;
|
|
1124
|
+
}).join(', ');
|
|
1125
|
+
const createTableStatement = `CREATE TABLE ${tableName} (${columnsDDL})`;
|
|
1126
|
+
await this.runQuery(createTableStatement, options);
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
case "dropTable":
|
|
1130
|
+
{
|
|
1131
|
+
// Default implementation for dropping table
|
|
1132
|
+
const { schema, table } = params;
|
|
1133
|
+
const tableName = schema ? `${schema}.${table}` : table;
|
|
1134
|
+
await this.runQuery(`DROP TABLE IF EXISTS ${tableName}`, options);
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
default:
|
|
1138
|
+
// Throw error for other unimplemented operations
|
|
1139
|
+
throw new Error(`Unsupported table action: ${action}`);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Generic type mapping (subclasses can override)
|
|
1144
|
+
*/ mapColumnType(type, isKey, length) {
|
|
1145
|
+
switch(type == null ? void 0 : type.toLowerCase()){
|
|
1146
|
+
case 'string':
|
|
1147
|
+
return length ? `VARCHAR(${length})` : isKey ? 'VARCHAR(255)' : 'VARCHAR(1000)';
|
|
1148
|
+
case 'number':
|
|
1149
|
+
return 'INT';
|
|
1150
|
+
case 'boolean':
|
|
1151
|
+
return 'BOOLEAN';
|
|
1152
|
+
case 'date':
|
|
1153
|
+
return 'DATE';
|
|
1154
|
+
case 'datetime':
|
|
1155
|
+
return 'TIMESTAMP';
|
|
1156
|
+
case 'object':
|
|
1157
|
+
return 'TEXT';
|
|
1158
|
+
default:
|
|
1159
|
+
return 'VARCHAR(1000)';
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1063
1162
|
constructor(...args){
|
|
1064
1163
|
super(...args);
|
|
1065
1164
|
this.syntax = "sql";
|
|
@@ -2029,4 +2128,40 @@ class Speech2TextChatModel extends BaseChatModel {
|
|
|
2029
2128
|
return 0;
|
|
2030
2129
|
}
|
|
2031
2130
|
|
|
2032
|
-
|
|
2131
|
+
/**
|
|
2132
|
+
* Get a Chat Model of copilot model and check it's token limitation, record the token usage
|
|
2133
|
+
*/ class CreateModelClientCommand extends Command {
|
|
2134
|
+
constructor(copilotModel, options){
|
|
2135
|
+
super();
|
|
2136
|
+
this.copilotModel = copilotModel;
|
|
2137
|
+
this.options = options;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
CreateModelClientCommand.type = '[AI Model] Create Model Client';
|
|
2141
|
+
|
|
2142
|
+
const AGENT_MIDDLEWARE_STRATEGY = 'AGENT_MIDDLEWARE_STRATEGY';
|
|
2143
|
+
const AgentMiddlewareStrategy = (provider)=>SetMetadata(AGENT_MIDDLEWARE_STRATEGY, provider);
|
|
2144
|
+
|
|
2145
|
+
let AgentMiddlewareRegistry = class AgentMiddlewareRegistry extends BaseStrategyRegistry {
|
|
2146
|
+
constructor(discoveryService, reflector){
|
|
2147
|
+
super(AGENT_MIDDLEWARE_STRATEGY, discoveryService, reflector);
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
AgentMiddlewareRegistry = __decorate([
|
|
2151
|
+
Injectable(),
|
|
2152
|
+
__metadata("design:type", Function),
|
|
2153
|
+
__metadata("design:paramtypes", [
|
|
2154
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
2155
|
+
typeof Reflector === "undefined" ? Object : Reflector
|
|
2156
|
+
])
|
|
2157
|
+
], AgentMiddlewareRegistry);
|
|
2158
|
+
|
|
2159
|
+
/**
|
|
2160
|
+
* jump targets (user facing)
|
|
2161
|
+
*/ const JUMP_TO_TARGETS = [
|
|
2162
|
+
"model",
|
|
2163
|
+
"tools",
|
|
2164
|
+
"end"
|
|
2165
|
+
];
|
|
2166
|
+
|
|
2167
|
+
export { AGENT_MIDDLEWARE_STRATEGY, AIModelProviderNotFoundException, AIModelProviderRegistry, AIModelProviderStrategy, AI_MODEL_PROVIDER, AdapterDataSourceStrategy, AgentMiddlewareRegistry, AgentMiddlewareStrategy, AiModelNotFoundException, BaseHTTPQueryRunner, BaseQueryRunner, BaseSQLQueryRunner, BaseTool, BaseToolset, BuiltinToolset, ChatOAICompatReasoningModel, CommonParameterRules, CreateModelClientCommand, CredentialsValidateFailedError, DATASOURCE_STRATEGY, DBCreateTableMode, DBProtocolEnum, DBSyntaxEnum, DBTableAction, DBTableDataAction, DOCUMENT_SOURCE_STRATEGY, DOCUMENT_TRANSFORMER_STRATEGY, DataSourceStrategy, DataSourceStrategyRegistry, DocumentSourceRegistry, DocumentSourceStrategy, DocumentTransformerRegistry, DocumentTransformerStrategy, IMAGE_UNDERSTANDING_STRATEGY, INTEGRATION_STRATEGY, ImageUnderstandingRegistry, ImageUnderstandingStrategy, IntegrationStrategyKey, IntegrationStrategyRegistry, JUMP_TO_TARGETS, KNOWLEDGE_STRATEGY, KnowledgeStrategyKey, KnowledgeStrategyRegistry, LLMUsage, LargeLanguageModel, ModelProvider, OpenAICompatibleReranker, PLUGIN_METADATA, PROVIDE_AI_MODEL_LLM, PROVIDE_AI_MODEL_MODERATION, PROVIDE_AI_MODEL_RERANK, PROVIDE_AI_MODEL_SPEECH2TEXT, PROVIDE_AI_MODEL_TEXT_EMBEDDING, PROVIDE_AI_MODEL_TTS, RETRIEVER_STRATEGY, RequestContext, RequestContextMiddleware, RerankModel, RetrieverRegistry, RetrieverStrategy, Speech2TextChatModel, SpeechToTextModel, TEXT_SPLITTER_STRATEGY, TOOLSET_STRATEGY, TextEmbeddingModelManager, TextSplitterRegistry, TextSplitterStrategy, TextToSpeechModel, ToolsetRegistry, ToolsetStrategy, VECTOR_STORE_STRATEGY, VectorStoreRegistry, VectorStoreStrategy, WORKFLOW_NODE_STRATEGY, WORKFLOW_TRIGGER_STRATEGY, WorkflowNodeRegistry, WorkflowNodeStrategy, WorkflowTriggerRegistry, WorkflowTriggerStrategy, WrapWorkflowNodeExecutionCommand, XpFileSystem, XpertServerPlugin, als, calcTokenUsage, countTokensSafe, createI18nInstance, createPluginLogger, downloadRemoteFile, getErrorMessage, getPositionList, getPositionMap, getRequestContext, isRemoteFile, loadYamlFile, mergeCredentials, mergeParentChildChunks, runWithRequestContext, sumTokenUsage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './middleware';
|
|
@@ -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,249 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* jump targets (user facing)
|
|
7
|
+
*/
|
|
8
|
+
export declare const JUMP_TO_TARGETS: readonly ["model", "tools", "end"];
|
|
9
|
+
export type JumpToTarget = (typeof JUMP_TO_TARGETS)[number];
|
|
10
|
+
export type PromiseOrValue<T> = T | Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Result type for middleware functions.
|
|
13
|
+
*/
|
|
14
|
+
export type MiddlewareResult<TState> = (TState & {
|
|
15
|
+
jumpTo?: JumpToTarget;
|
|
16
|
+
}) | void;
|
|
17
|
+
/**
|
|
18
|
+
* Handler function type for the beforeAgent hook.
|
|
19
|
+
* Called once at the start of agent invocation before any model calls or tool executions.
|
|
20
|
+
*
|
|
21
|
+
* @param state - The current agent state (includes both middleware state and built-in state)
|
|
22
|
+
* @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
23
|
+
* @returns A middleware result containing partial state updates or undefined to pass through
|
|
24
|
+
*/
|
|
25
|
+
type BeforeAgentHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
|
|
26
|
+
/**
|
|
27
|
+
* Hook type for the beforeAgent lifecycle event.
|
|
28
|
+
* Can be either a handler function or an object with a handler and optional jump targets.
|
|
29
|
+
* This hook is called once at the start of the agent invocation.
|
|
30
|
+
*/
|
|
31
|
+
export type BeforeAgentHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeAgentHandler<TSchema, TContext> | {
|
|
32
|
+
hook: BeforeAgentHandler<TSchema, TContext>;
|
|
33
|
+
canJumpTo?: JumpToTarget[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Handler function type for the beforeModel hook.
|
|
37
|
+
* Called before the model is invoked and before the wrapModelCall hook.
|
|
38
|
+
*
|
|
39
|
+
* @param state - The current agent state (includes both middleware state and built-in state)
|
|
40
|
+
* @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
41
|
+
* @returns A middleware result containing partial state updates or undefined to pass through
|
|
42
|
+
*/
|
|
43
|
+
export type BeforeModelHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
|
|
44
|
+
/**
|
|
45
|
+
* Hook type for the beforeModel lifecycle event.
|
|
46
|
+
* Can be either a handler function or an object with a handler and optional jump targets.
|
|
47
|
+
* This hook is called before each model invocation.
|
|
48
|
+
*/
|
|
49
|
+
export type BeforeModelHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = BeforeModelHandler<TSchema, TContext> | {
|
|
50
|
+
hook: BeforeModelHandler<TSchema, TContext>;
|
|
51
|
+
canJumpTo?: JumpToTarget[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Handler function type for the afterModel hook.
|
|
55
|
+
* Called after the model is invoked and before any tools are called.
|
|
56
|
+
* Allows modifying the agent state after model invocation, e.g., to update tool call parameters.
|
|
57
|
+
*
|
|
58
|
+
* @param state - The current agent state (includes both middleware state and built-in state)
|
|
59
|
+
* @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
60
|
+
* @returns A middleware result containing partial state updates or undefined to pass through
|
|
61
|
+
*/
|
|
62
|
+
export type AfterModelHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
|
|
63
|
+
/**
|
|
64
|
+
* Hook type for the afterModel lifecycle event.
|
|
65
|
+
* Can be either a handler function or an object with a handler and optional jump targets.
|
|
66
|
+
* This hook is called after each model invocation.
|
|
67
|
+
*/
|
|
68
|
+
export type AfterModelHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterModelHandler<TSchema, TContext> | {
|
|
69
|
+
hook: AfterModelHandler<TSchema, TContext>;
|
|
70
|
+
canJumpTo?: JumpToTarget[];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Handler function type for the afterAgent hook.
|
|
74
|
+
* Called once at the end of agent invocation after all model calls and tool executions are complete.
|
|
75
|
+
*
|
|
76
|
+
* @param state - The current agent state (includes both middleware state and built-in state)
|
|
77
|
+
* @param runtime - The runtime context containing metadata, signal, writer, interrupt, etc.
|
|
78
|
+
* @returns A middleware result containing partial state updates or undefined to pass through
|
|
79
|
+
*/
|
|
80
|
+
type AfterAgentHandler<TSchema, TContext> = (state: TSchema, runtime: TContext) => PromiseOrValue<MiddlewareResult<Partial<TSchema>>>;
|
|
81
|
+
/**
|
|
82
|
+
* Hook type for the afterAgent lifecycle event.
|
|
83
|
+
* Can be either a handler function or an object with a handler and optional jump targets.
|
|
84
|
+
* This hook is called once at the end of the agent invocation.
|
|
85
|
+
*/
|
|
86
|
+
export type AfterAgentHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = AfterAgentHandler<TSchema, TContext> | {
|
|
87
|
+
hook: AfterAgentHandler<TSchema, TContext>;
|
|
88
|
+
canJumpTo?: JumpToTarget[];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Configuration for modifying a model call at runtime.
|
|
92
|
+
* All fields are optional and only provided fields will override defaults.
|
|
93
|
+
*
|
|
94
|
+
* @template TState - The agent's state type, must extend Record<string, unknown>. Defaults to Record<string, unknown>.
|
|
95
|
+
* @template TContext - The runtime context type for accessing metadata and control flow. Defaults to unknown.
|
|
96
|
+
*/
|
|
97
|
+
export interface ModelRequest<TState = any, TContext = unknown> {
|
|
98
|
+
/**
|
|
99
|
+
* The model to use for this step.
|
|
100
|
+
*/
|
|
101
|
+
model: LanguageModelLike;
|
|
102
|
+
/**
|
|
103
|
+
* The messages to send to the model.
|
|
104
|
+
*/
|
|
105
|
+
messages: BaseMessage[];
|
|
106
|
+
systemMessage?: SystemMessage;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Handler function type for wrapping model calls.
|
|
110
|
+
* Takes a model request and returns the AI message response.
|
|
111
|
+
*
|
|
112
|
+
* @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime
|
|
113
|
+
* @returns The AI message response from the model
|
|
114
|
+
*/
|
|
115
|
+
export type WrapModelCallHandler<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema, TContext>) => PromiseOrValue<AIMessage>;
|
|
116
|
+
/**
|
|
117
|
+
* Wrapper function type for the wrapModelCall hook.
|
|
118
|
+
* Allows middleware to intercept and modify model execution.
|
|
119
|
+
* This enables you to:
|
|
120
|
+
* - Modify the request before calling the model (e.g., change system prompt, add/remove tools)
|
|
121
|
+
* - Handle errors and retry with different parameters
|
|
122
|
+
* - Post-process the response
|
|
123
|
+
* - Implement custom caching, logging, or other cross-cutting concerns
|
|
124
|
+
*
|
|
125
|
+
* @param request - The model request containing all parameters needed for the model call
|
|
126
|
+
* @param handler - The function that invokes the model. Call this with a ModelRequest to get the response
|
|
127
|
+
* @returns The AI message response from the model (or a modified version)
|
|
128
|
+
*/
|
|
129
|
+
export type WrapModelCallHook<TSchema extends InteropZodObject | undefined = undefined, TContext = unknown> = (request: ModelRequest<TSchema, TContext>, handler: WrapModelCallHandler<TSchema, TContext>) => PromiseOrValue<AIMessage>;
|
|
130
|
+
export interface AgentMiddleware<TSchema extends InteropZodObject | undefined = any, TContextSchema extends InteropZodObject | undefined = any, TFullContext = any> {
|
|
131
|
+
/**
|
|
132
|
+
* The name of the middleware.
|
|
133
|
+
*/
|
|
134
|
+
name: string;
|
|
135
|
+
/**
|
|
136
|
+
* The schema of the middleware state. Middleware state is persisted between multiple invocations. It can be either:
|
|
137
|
+
* - A Zod object
|
|
138
|
+
* - A Zod optional object
|
|
139
|
+
* - A Zod default object
|
|
140
|
+
* - Undefined
|
|
141
|
+
*/
|
|
142
|
+
stateSchema?: TSchema;
|
|
143
|
+
/**
|
|
144
|
+
* The schema of the middleware context. Middleware context is read-only and not persisted between multiple invocations. It can be either:
|
|
145
|
+
* - A Zod object
|
|
146
|
+
* - A Zod optional object
|
|
147
|
+
* - A Zod default object
|
|
148
|
+
* - Undefined
|
|
149
|
+
*/
|
|
150
|
+
contextSchema?: TContextSchema;
|
|
151
|
+
tools?: DynamicStructuredTool[];
|
|
152
|
+
beforeAgent?: BeforeAgentHook<TSchema, TFullContext>;
|
|
153
|
+
beforeModel?: BeforeModelHook<TSchema, TFullContext>;
|
|
154
|
+
afterModel?: AfterModelHook<TSchema, TFullContext>;
|
|
155
|
+
afterAgent?: AfterAgentHook<TSchema, TFullContext>;
|
|
156
|
+
/**
|
|
157
|
+
* Wraps the model invocation with custom logic. This allows you to:
|
|
158
|
+
* - Modify the request before calling the model
|
|
159
|
+
* - Handle errors and retry with different parameters
|
|
160
|
+
* - Post-process the response
|
|
161
|
+
* - Implement custom caching, logging, or other cross-cutting concerns
|
|
162
|
+
*
|
|
163
|
+
* @param request - The model request containing model, messages, systemPrompt, tools, state, and runtime.
|
|
164
|
+
* @param handler - The function that invokes the model. Call this with a ModelRequest to get the response.
|
|
165
|
+
* @returns The response from the model (or a modified version).
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* wrapModelCall: async (request, handler) => {
|
|
170
|
+
* // Modify request before calling
|
|
171
|
+
* const modifiedRequest = { ...request, systemPrompt: "You are helpful" };
|
|
172
|
+
*
|
|
173
|
+
* try {
|
|
174
|
+
* // Call the model
|
|
175
|
+
* return await handler(modifiedRequest);
|
|
176
|
+
* } catch (error) {
|
|
177
|
+
* // Handle errors and retry with fallback
|
|
178
|
+
* const fallbackRequest = { ...request, model: fallbackModel };
|
|
179
|
+
* return await handler(fallbackRequest);
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
wrapModelCall?: WrapModelCallHook<TSchema, TFullContext>;
|
|
185
|
+
/**
|
|
186
|
+
* Wraps tool execution with custom logic. This allows you to:
|
|
187
|
+
* - Modify tool call parameters before execution
|
|
188
|
+
* - Handle errors and retry with different parameters
|
|
189
|
+
* - Post-process tool results
|
|
190
|
+
* - Implement caching, logging, authentication, or other cross-cutting concerns
|
|
191
|
+
* - Return Command objects for advanced control flow
|
|
192
|
+
*
|
|
193
|
+
* The handler receives a ToolCallRequest containing the tool call, state, and runtime,
|
|
194
|
+
* along with a handler function to execute the actual tool.
|
|
195
|
+
*
|
|
196
|
+
* @param request - The tool call request containing toolCall, state, and runtime.
|
|
197
|
+
* @param handler - The function that executes the tool. Call this with a ToolCallRequest to get the result.
|
|
198
|
+
* @returns The tool result as a ToolMessage or a Command for advanced control flow.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* wrapToolCall: async (request, handler) => {
|
|
203
|
+
* console.log(`Calling tool: ${request.tool.name}`);
|
|
204
|
+
* console.log(`Tool description: ${request.tool.description}`);
|
|
205
|
+
*
|
|
206
|
+
* try {
|
|
207
|
+
* // Execute the tool
|
|
208
|
+
* const result = await handler(request);
|
|
209
|
+
* console.log(`Tool ${request.tool.name} succeeded`);
|
|
210
|
+
* return result;
|
|
211
|
+
* } catch (error) {
|
|
212
|
+
* console.error(`Tool ${request.tool.name} failed:`, error);
|
|
213
|
+
* // Could return a custom error message or retry
|
|
214
|
+
* throw error;
|
|
215
|
+
* }
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @example Authentication
|
|
220
|
+
* ```ts
|
|
221
|
+
* wrapToolCall: async (request, handler) => {
|
|
222
|
+
* // Check if user is authorized for this tool
|
|
223
|
+
* if (!request.runtime.context.isAuthorized(request.tool.name)) {
|
|
224
|
+
* return new ToolMessage({
|
|
225
|
+
* content: "Unauthorized to call this tool",
|
|
226
|
+
* tool_call_id: request.toolCall.id,
|
|
227
|
+
* });
|
|
228
|
+
* }
|
|
229
|
+
* return handler(request);
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @example Caching
|
|
234
|
+
* ```ts
|
|
235
|
+
* const cache = new Map();
|
|
236
|
+
* wrapToolCall: async (request, handler) => {
|
|
237
|
+
* const cacheKey = `${request.tool.name}:${JSON.stringify(request.toolCall.args)}`;
|
|
238
|
+
* if (cache.has(cacheKey)) {
|
|
239
|
+
* return cache.get(cacheKey);
|
|
240
|
+
* }
|
|
241
|
+
* const result = await handler(request);
|
|
242
|
+
* cache.set(cacheKey, result);
|
|
243
|
+
* return result;
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
wrapToolCall?: (request: ModelRequest<TSchema, TFullContext>, handler: WrapModelCallHandler<TSchema, TFullContext>) => PromiseOrValue<AIMessage>;
|
|
248
|
+
}
|
|
249
|
+
export {};
|
|
@@ -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';
|
|
@@ -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
|
+
}
|
|
@@ -155,9 +155,21 @@ export interface ColumnDef {
|
|
|
155
155
|
*/
|
|
156
156
|
isKey: boolean;
|
|
157
157
|
/**
|
|
158
|
-
* Is required column
|
|
158
|
+
* Is required column (NOT NULL)
|
|
159
159
|
*/
|
|
160
160
|
required?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Is unique column
|
|
163
|
+
*/
|
|
164
|
+
unique?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Auto increment (for number type)
|
|
167
|
+
*/
|
|
168
|
+
autoIncrement?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Default value
|
|
171
|
+
*/
|
|
172
|
+
defaultValue?: string;
|
|
161
173
|
/**
|
|
162
174
|
* length of type for column: varchar, decimal ...
|
|
163
175
|
*/
|
|
@@ -166,6 +178,14 @@ export interface ColumnDef {
|
|
|
166
178
|
* fraction of type for decimal
|
|
167
179
|
*/
|
|
168
180
|
fraction?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Enum values (for ENUM type)
|
|
183
|
+
*/
|
|
184
|
+
enumValues?: string[];
|
|
185
|
+
/**
|
|
186
|
+
* Set values (for SET type)
|
|
187
|
+
*/
|
|
188
|
+
setValues?: string[];
|
|
169
189
|
}
|
|
170
190
|
export interface CreationTable {
|
|
171
191
|
catalog?: string;
|
|
@@ -242,6 +262,14 @@ export declare abstract class BaseSQLQueryRunner<T extends SQLAdapterOptions = S
|
|
|
242
262
|
get port(): string | number;
|
|
243
263
|
abstract createCatalog?(catalog: string): Promise<void>;
|
|
244
264
|
ping(): Promise<void>;
|
|
265
|
+
/**
|
|
266
|
+
* Default implementation for table operations
|
|
267
|
+
*/
|
|
268
|
+
tableOp(action: DBTableAction, params: DBTableOperationParams, options?: QueryOptions): Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Generic type mapping (subclasses can override)
|
|
271
|
+
*/
|
|
272
|
+
protected mapColumnType(type: string, isKey: boolean, length?: number): string;
|
|
245
273
|
}
|
|
246
274
|
export interface File {
|
|
247
275
|
/** Name of the form field associated with this file. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './wrap-workflow-node-execution.command';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IXpertAgentExecution, JSONValue } from '@metad/contracts';
|
|
2
|
+
import { Command } from '@nestjs/cqrs';
|
|
3
|
+
import { Subscriber } from 'rxjs';
|
|
4
|
+
/**
|
|
5
|
+
* Wrap Workflow Node Execution Command
|
|
6
|
+
*/
|
|
7
|
+
export declare class WrapWorkflowNodeExecutionCommand<T = any> extends Command<T> {
|
|
8
|
+
readonly fuc: (execution: Partial<IXpertAgentExecution>) => Promise<{
|
|
9
|
+
output?: string | JSONValue;
|
|
10
|
+
state: T;
|
|
11
|
+
}>;
|
|
12
|
+
readonly params: {
|
|
13
|
+
execution: Partial<IXpertAgentExecution>;
|
|
14
|
+
subscriber?: Subscriber<MessageEvent>;
|
|
15
|
+
catchError?: (error: Error) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
static readonly type = "[Workflow] Wrap Workflow Node Execution";
|
|
18
|
+
constructor(fuc: (execution: Partial<IXpertAgentExecution>) => Promise<{
|
|
19
|
+
output?: string | JSONValue;
|
|
20
|
+
state: T;
|
|
21
|
+
}>, params: {
|
|
22
|
+
execution: Partial<IXpertAgentExecution>;
|
|
23
|
+
subscriber?: Subscriber<MessageEvent>;
|
|
24
|
+
catchError?: (error: Error) => Promise<void>;
|
|
25
|
+
});
|
|
26
|
+
}
|