@xpert-ai/plugin-sdk 3.7.1 → 3.8.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/index.cjs.js +851 -834
- package/index.esm.js +826 -837
- package/package.json +5 -1
- package/src/index.d.ts +2 -0
- package/src/lib/agent/handoff/agent-chat.contract.d.ts +20 -0
- package/src/lib/agent/handoff/handoff-processor.decorator.d.ts +11 -0
- package/src/lib/agent/handoff/handoff-processor.registry.d.ts +6 -0
- package/src/lib/agent/handoff/handoff.interface.d.ts +17 -0
- package/src/lib/agent/handoff/index.d.ts +6 -0
- package/src/lib/agent/handoff/message-type.d.ts +24 -0
- package/src/lib/agent/handoff/types.d.ts +110 -0
- package/src/lib/agent/index.d.ts +1 -0
- package/src/lib/agent/middleware/runtime.d.ts +2 -0
- package/src/lib/agent/middleware/strategy.interface.d.ts +5 -1
- package/src/lib/agent/middleware/types.d.ts +73 -8
- package/src/lib/ai-model/ai-model.d.ts +3 -1
- package/src/lib/ai-model/utils/index.d.ts +1 -0
- package/src/lib/ai-model/utils/limits.d.ts +4 -0
- package/src/lib/channel/cancel-conversation.command.d.ts +14 -0
- package/src/lib/channel/index.d.ts +4 -0
- package/src/lib/channel/strategy.decorator.d.ts +23 -0
- package/src/lib/channel/strategy.interface.d.ts +345 -0
- package/src/lib/channel/strategy.registry.d.ts +30 -0
- package/src/lib/core/permissions/analytics.d.ts +46 -0
- package/src/lib/core/{permissions.d.ts → permissions/general.d.ts} +9 -12
- package/src/lib/core/permissions/handoff.d.ts +36 -0
- package/src/lib/core/permissions/index.d.ts +24 -0
- package/src/lib/core/permissions/operation.d.ts +8 -0
- package/src/lib/core/permissions/user.d.ts +29 -0
- package/src/lib/core/utils.d.ts +6 -0
- package/src/lib/integration/strategy.interface.d.ts +3 -1
- package/src/lib/sandbox/index.d.ts +8 -0
- package/src/lib/sandbox/protocol.d.ts +265 -0
- package/src/lib/sandbox/sandbox.d.ts +70 -0
- package/src/lib/sandbox/sandbox.decorator.d.ts +2 -0
- package/src/lib/sandbox/sandbox.interface.d.ts +38 -0
- package/src/lib/sandbox/sandbox.registry.d.ts +6 -0
- package/src/lib/toolset/strategy.interface.d.ts +2 -6
- package/src/lib/types.d.ts +7 -1
- package/src/lib/workflow/node/strategy.interface.d.ts +4 -2
- package/src/lib/workflow/trigger/strategy.interface.d.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,16 +20,20 @@
|
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@langchain/core": "*",
|
|
22
22
|
"@metad/contracts": "*",
|
|
23
|
+
"@metad/ocap-core": "*",
|
|
23
24
|
"@nestjs/common": "*",
|
|
24
25
|
"@nestjs/core": "*",
|
|
25
26
|
"@nestjs/cqrs": "*",
|
|
27
|
+
"ajv": "*",
|
|
26
28
|
"lodash-es": "*",
|
|
27
29
|
"i18next-fs-backend": "*",
|
|
28
30
|
"i18next": "*",
|
|
31
|
+
"json-schema": "*",
|
|
29
32
|
"jsonwebtoken": "*",
|
|
30
33
|
"fs": "*",
|
|
31
34
|
"path": "*",
|
|
32
35
|
"passport-jwt": "*",
|
|
36
|
+
"rxjs": "*",
|
|
33
37
|
"stream": "*",
|
|
34
38
|
"yaml": "*",
|
|
35
39
|
"zod": "*"
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TChatOptions, TChatRequest } from '@metad/contracts';
|
|
2
|
+
export declare const AGENT_CHAT_DISPATCH_MESSAGE_TYPE: import("./message-type").StructuredHandoffMessageType;
|
|
3
|
+
export interface AgentChatCallbackTarget {
|
|
4
|
+
messageType: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
context?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface AgentChatDispatchPayload extends Record<string, unknown> {
|
|
9
|
+
request: TChatRequest;
|
|
10
|
+
options: TChatOptions;
|
|
11
|
+
callback: AgentChatCallbackTarget;
|
|
12
|
+
}
|
|
13
|
+
export interface AgentChatCallbackEnvelopePayload extends Record<string, unknown> {
|
|
14
|
+
kind: 'stream' | 'complete' | 'error';
|
|
15
|
+
sourceMessageId: string;
|
|
16
|
+
sequence: number;
|
|
17
|
+
event?: unknown;
|
|
18
|
+
error?: string;
|
|
19
|
+
context?: Record<string, unknown>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HandoffProcessorMetadata } from './handoff.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Handoff Processor meta key。
|
|
4
|
+
*/
|
|
5
|
+
export declare const HANDOFF_PROCESSOR_STRATEGY = "HANDOFF_PROCESSOR_STRATEGY";
|
|
6
|
+
/**
|
|
7
|
+
* Declare on a provider:
|
|
8
|
+
* 1) Which message types it handles
|
|
9
|
+
* 2) Default execution policy (lane/timeout)
|
|
10
|
+
*/
|
|
11
|
+
export declare function HandoffProcessorStrategy(provider: string, metadata: HandoffProcessorMetadata): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IHandoffProcessor } from './handoff.interface';
|
|
4
|
+
export declare class HandoffProcessorRegistry extends BaseStrategyRegistry<IHandoffProcessor> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandoffMessage, ProcessContext, ProcessorPolicy, ProcessResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Handoff Processor interface.
|
|
4
|
+
* - Processor focus only on message processing logic; scheduling, retries, concurrency, and cancellation are handled uniformly by Dispatcher + Queue.
|
|
5
|
+
*/
|
|
6
|
+
export interface IHandoffProcessor<TPayload extends Record<string, unknown> = Record<string, unknown>> {
|
|
7
|
+
process(message: HandoffMessage<TPayload>, ctx: ProcessContext): Promise<ProcessResult>;
|
|
8
|
+
}
|
|
9
|
+
export interface HandoffProcessorMetadata {
|
|
10
|
+
types: string[];
|
|
11
|
+
policy: ProcessorPolicy;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedHandoffProcessor {
|
|
14
|
+
type: string;
|
|
15
|
+
processor: IHandoffProcessor;
|
|
16
|
+
metadata: HandoffProcessorMetadata;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured message types (suggested format):
|
|
3
|
+
* - channel.{provider}.{action}.v{number}
|
|
4
|
+
* - agent.{action}.v{number}
|
|
5
|
+
* - system.{action}.v{number}
|
|
6
|
+
* - plugin.{domain}.{action}.v{number}
|
|
7
|
+
*
|
|
8
|
+
* Note: At runtime, any string type is still allowed, facilitating dynamic extension by plugins.
|
|
9
|
+
*/
|
|
10
|
+
export type StructuredHandoffMessageType = `channel.${string}.${string}.v${number}` | `agent.${string}.v${number}` | `system.${string}.v${number}` | `plugin.${string}.${string}.v${number}`;
|
|
11
|
+
/**
|
|
12
|
+
* Unified construction of channel message types to avoid manual string errors.
|
|
13
|
+
* Example: channel.lark.inbound.v1
|
|
14
|
+
*/
|
|
15
|
+
export declare function defineChannelMessageType(provider: string, action: string, version: number): StructuredHandoffMessageType;
|
|
16
|
+
/**
|
|
17
|
+
* Unified construction of agent message types.
|
|
18
|
+
* Example: agent.handoff.v1
|
|
19
|
+
*/
|
|
20
|
+
export declare function defineAgentMessageType(action: string, version: number): StructuredHandoffMessageType;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a type conforms to the structured naming convention (format only, no semantic validation).
|
|
23
|
+
*/
|
|
24
|
+
export declare function isStructuredMessageType(type: string): boolean;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff execution types.
|
|
3
|
+
*
|
|
4
|
+
* Note:
|
|
5
|
+
* - Two-gate lane/session permit logic has been removed.
|
|
6
|
+
* - Lane is now an execution tag for observability and soft policy only.
|
|
7
|
+
*/
|
|
8
|
+
export type LaneName = 'main' | 'subagent' | 'cron' | 'nested';
|
|
9
|
+
export type RunSource = 'chat' | 'xpert' | 'lark' | 'analytics' | 'api';
|
|
10
|
+
export interface RunMetadata {
|
|
11
|
+
runId: string;
|
|
12
|
+
sessionKey: string;
|
|
13
|
+
lane: LaneName;
|
|
14
|
+
source: RunSource;
|
|
15
|
+
startedAt: number;
|
|
16
|
+
expiresAt?: number;
|
|
17
|
+
controller: AbortController;
|
|
18
|
+
conversationId?: string;
|
|
19
|
+
executionId?: string;
|
|
20
|
+
integrationId?: string;
|
|
21
|
+
userId?: string;
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface LaneStats {
|
|
25
|
+
lane: string;
|
|
26
|
+
active: number;
|
|
27
|
+
queued: number;
|
|
28
|
+
maxConcurrent: number;
|
|
29
|
+
draining: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface RunOptions {
|
|
32
|
+
runId: string;
|
|
33
|
+
sessionKey?: string;
|
|
34
|
+
globalLane?: LaneName;
|
|
35
|
+
abortController: AbortController;
|
|
36
|
+
source?: RunSource;
|
|
37
|
+
conversationId?: string;
|
|
38
|
+
executionId?: string;
|
|
39
|
+
integrationId?: string;
|
|
40
|
+
userId?: string;
|
|
41
|
+
tenantId?: string;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ExecutionConfig {
|
|
45
|
+
lanes: Record<LaneName, number>;
|
|
46
|
+
runTtlMs: number;
|
|
47
|
+
}
|
|
48
|
+
export declare const DEFAULT_EXECUTION_CONFIG: ExecutionConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Handoff message envelope (v1).
|
|
51
|
+
* Using `type` with a string allows plugins to dynamically expand at runtime without needing to modify the core type definition.
|
|
52
|
+
*/
|
|
53
|
+
export interface HandoffMessage<TPayload extends Record<string, unknown> = Record<string, unknown>> {
|
|
54
|
+
id: string;
|
|
55
|
+
/**
|
|
56
|
+
* Message type, used for processor resolution.
|
|
57
|
+
*/
|
|
58
|
+
type: string;
|
|
59
|
+
version: number;
|
|
60
|
+
tenantId: string;
|
|
61
|
+
sessionKey: string;
|
|
62
|
+
businessKey: string;
|
|
63
|
+
attempt: number;
|
|
64
|
+
maxAttempts: number;
|
|
65
|
+
enqueuedAt: number;
|
|
66
|
+
traceId: string;
|
|
67
|
+
parentMessageId?: string;
|
|
68
|
+
payload: TPayload;
|
|
69
|
+
headers?: HandoffMessageHeaders;
|
|
70
|
+
}
|
|
71
|
+
export interface HandoffMessageHeaders extends Record<string, string> {
|
|
72
|
+
organizationId?: string;
|
|
73
|
+
userId?: string;
|
|
74
|
+
language?: string;
|
|
75
|
+
threadId?: string;
|
|
76
|
+
conversationId?: string;
|
|
77
|
+
sourceAgent?: string;
|
|
78
|
+
targetAgent?: string;
|
|
79
|
+
source?: RunSource;
|
|
80
|
+
requestedLane?: LaneName;
|
|
81
|
+
integrationId?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Processor execution policy: declared by the Processor, executed uniformly by the Dispatcher.
|
|
85
|
+
*/
|
|
86
|
+
export interface ProcessorPolicy {
|
|
87
|
+
lane: LaneName;
|
|
88
|
+
timeoutMs?: number;
|
|
89
|
+
}
|
|
90
|
+
export interface ProcessContext {
|
|
91
|
+
runId: string;
|
|
92
|
+
traceId: string;
|
|
93
|
+
abortSignal: AbortSignal;
|
|
94
|
+
/**
|
|
95
|
+
* Optional local-process event channel for queue waiters (e.g. SSE connection awaiting this message).
|
|
96
|
+
* This is intentionally process-local and best-effort.
|
|
97
|
+
*/
|
|
98
|
+
emit?: (event: unknown) => void;
|
|
99
|
+
}
|
|
100
|
+
export type ProcessResult = {
|
|
101
|
+
status: 'ok';
|
|
102
|
+
outbound?: HandoffMessage[];
|
|
103
|
+
} | {
|
|
104
|
+
status: 'retry';
|
|
105
|
+
delayMs: number;
|
|
106
|
+
reason?: string;
|
|
107
|
+
} | {
|
|
108
|
+
status: 'dead';
|
|
109
|
+
reason: string;
|
|
110
|
+
};
|
package/src/lib/agent/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Runtime as LangGraphRuntime } from "@langchain/langgraph";
|
|
2
2
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
3
|
+
import { TSandboxConfigurable } from "@metad/contracts";
|
|
3
4
|
/**
|
|
4
5
|
* Type for the agent's built-in state properties.
|
|
5
6
|
*/
|
|
@@ -51,6 +52,7 @@ export type WithMaybeContext<TContext> = undefined extends TContext ? {
|
|
|
51
52
|
export type Runtime<TContext = unknown> = Partial<Omit<LangGraphRuntime<TContext>, "context" | "configurable">> & WithMaybeContext<TContext> & {
|
|
52
53
|
configurable?: {
|
|
53
54
|
thread_id?: string;
|
|
55
|
+
sandbox?: TSandboxConfigurable | null;
|
|
54
56
|
[key: string]: unknown;
|
|
55
57
|
};
|
|
56
58
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IWFNMiddleware, TAgentMiddlewareMeta } from '@metad/contracts';
|
|
2
|
-
import {
|
|
2
|
+
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
3
|
+
import { RunnableToolLike } from '@langchain/core/runnables';
|
|
4
|
+
import { AgentMiddleware } from './types';
|
|
5
|
+
import { PromiseOrValue } from '../../types';
|
|
3
6
|
export interface IAgentMiddlewareContext {
|
|
4
7
|
tenantId: string;
|
|
5
8
|
userId: string;
|
|
@@ -9,6 +12,7 @@ export interface IAgentMiddlewareContext {
|
|
|
9
12
|
xpertId?: string;
|
|
10
13
|
agentKey?: string;
|
|
11
14
|
node: IWFNMiddleware;
|
|
15
|
+
tools: Map<string, StructuredToolInterface | RunnableToolLike>;
|
|
12
16
|
}
|
|
13
17
|
export interface IAgentMiddlewareStrategy<T = unknown> {
|
|
14
18
|
meta: TAgentMiddlewareMeta;
|
|
@@ -1,14 +1,21 @@
|
|
|
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 { Command } from '@langchain/langgraph';
|
|
8
|
+
import { AgentBuiltInState, Runtime } from './runtime';
|
|
9
|
+
import { PromiseOrValue } from '../../types';
|
|
10
|
+
export type ServerTool = Record<string, unknown>;
|
|
11
|
+
export type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
|
|
12
|
+
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;
|
|
13
|
+
type NormalizeContextSchema<TContextSchema extends InteropZodObject | undefined = undefined> = TContextSchema extends InteropZodObject ? InferInteropZodOutput<TContextSchema> : never;
|
|
6
14
|
/**
|
|
7
15
|
* jump targets (user facing)
|
|
8
16
|
*/
|
|
9
17
|
export declare const JUMP_TO_TARGETS: readonly ["model", "tools", "end"];
|
|
10
18
|
export type JumpToTarget = (typeof JUMP_TO_TARGETS)[number];
|
|
11
|
-
export type PromiseOrValue<T> = T | Promise<T>;
|
|
12
19
|
/**
|
|
13
20
|
* Result type for middleware functions.
|
|
14
21
|
*/
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BaseLanguageModel } from "@langchain/core/language_models/base";
|
|
2
|
+
import { ICopilotModel } from "@metad/contracts";
|
|
3
|
+
export declare function getModelContextSize(input: BaseLanguageModel | ICopilotModel): number | undefined;
|
|
4
|
+
export declare function normalizeContextSize(value: unknown): number | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ICommand } from '@nestjs/cqrs';
|
|
2
|
+
export declare class CancelConversationCommand implements ICommand {
|
|
3
|
+
readonly input: {
|
|
4
|
+
conversationId?: string;
|
|
5
|
+
threadId?: string;
|
|
6
|
+
executionId?: string;
|
|
7
|
+
};
|
|
8
|
+
static readonly type = "[Chat Conversation] Cancel";
|
|
9
|
+
constructor(input: {
|
|
10
|
+
conversationId?: string;
|
|
11
|
+
threadId?: string;
|
|
12
|
+
executionId?: string;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata key for chat channel
|
|
3
|
+
*/
|
|
4
|
+
export declare const CHAT_CHANNEL = "CHAT_CHANNEL";
|
|
5
|
+
/**
|
|
6
|
+
* Decorator for chat channel implementations
|
|
7
|
+
*
|
|
8
|
+
* Use this decorator to register a chat channel implementation.
|
|
9
|
+
* The decorated class will be automatically discovered and registered
|
|
10
|
+
* to ChatChannelRegistry on module initialization.
|
|
11
|
+
*
|
|
12
|
+
* @param type - The channel type identifier (e.g., 'lark', 'wecom', 'dingtalk')
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @Injectable()
|
|
17
|
+
* @ChatChannel('lark')
|
|
18
|
+
* export class LarkChatChannel implements IChatChannel {
|
|
19
|
+
* // Implementation
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const ChatChannel: (type: string) => import("@nestjs/common").CustomDecorator<string>;
|