@aigne/core 1.15.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +9 -7
- package/README.zh.md +9 -7
- package/lib/cjs/agents/agent.d.ts +168 -29
- package/lib/cjs/agents/agent.js +152 -56
- package/lib/cjs/agents/ai-agent.d.ts +7 -7
- package/lib/cjs/agents/ai-agent.js +19 -15
- package/lib/{esm/models → cjs/agents}/chat-model.d.ts +29 -19
- package/lib/cjs/{models → agents}/chat-model.js +56 -15
- package/lib/cjs/agents/guide-rail-agent.d.ts +62 -0
- package/lib/cjs/agents/guide-rail-agent.js +14 -0
- package/lib/cjs/agents/mcp-agent.d.ts +3 -4
- package/lib/cjs/agents/mcp-agent.js +11 -11
- package/lib/cjs/agents/team-agent.d.ts +7 -8
- package/lib/cjs/agents/team-agent.js +10 -10
- package/lib/cjs/agents/user-agent.d.ts +4 -4
- package/lib/cjs/agents/user-agent.js +10 -10
- package/lib/cjs/aigne/aigne.d.ts +13 -11
- package/lib/cjs/aigne/aigne.js +7 -6
- package/lib/cjs/aigne/context.d.ts +19 -8
- package/lib/cjs/aigne/context.js +27 -7
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/loader/agent-yaml.d.ts +2 -2
- package/lib/cjs/loader/index.d.ts +18 -11
- package/lib/cjs/loader/index.js +8 -27
- package/lib/cjs/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/index.js +69 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrate.js +53 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +33 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/cjs/memory/default-memory/default-memory-storage/models/memory.js +32 -0
- package/lib/cjs/memory/default-memory/index.d.ts +10 -0
- package/lib/cjs/memory/{default-memory.js → default-memory/index.js} +16 -25
- package/lib/cjs/memory/default-memory/storage.d.ts +13 -0
- package/lib/cjs/memory/default-memory/storage.js +6 -0
- package/lib/cjs/memory/memory.d.ts +3 -2
- package/lib/cjs/memory/memory.js +1 -1
- package/lib/cjs/memory/retriever.d.ts +2 -2
- package/lib/cjs/prompt/prompt-builder.d.ts +10 -4
- package/lib/cjs/prompt/prompt-builder.js +4 -4
- package/lib/cjs/prompt/template.d.ts +3 -3
- package/lib/cjs/utils/json-schema.js +1 -1
- package/lib/cjs/utils/logger.d.ts +33 -8
- package/lib/cjs/utils/logger.js +63 -5
- package/lib/cjs/utils/model-utils.d.ts +1 -1
- package/lib/cjs/utils/stream-utils.d.ts +3 -1
- package/lib/cjs/utils/stream-utils.js +31 -1
- package/lib/cjs/utils/type-utils.d.ts +7 -2
- package/lib/dts/agents/agent.d.ts +168 -29
- package/lib/dts/agents/ai-agent.d.ts +7 -7
- package/lib/{cjs/models → dts/agents}/chat-model.d.ts +29 -19
- package/lib/dts/agents/guide-rail-agent.d.ts +62 -0
- package/lib/dts/agents/mcp-agent.d.ts +3 -4
- package/lib/dts/agents/team-agent.d.ts +7 -8
- package/lib/dts/agents/user-agent.d.ts +4 -4
- package/lib/dts/aigne/aigne.d.ts +13 -11
- package/lib/dts/aigne/context.d.ts +19 -8
- package/lib/dts/index.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +2 -2
- package/lib/dts/loader/index.d.ts +18 -11
- package/lib/dts/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/dts/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/dts/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/dts/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/dts/memory/default-memory/index.d.ts +10 -0
- package/lib/dts/memory/default-memory/storage.d.ts +13 -0
- package/lib/dts/memory/memory.d.ts +3 -2
- package/lib/dts/memory/retriever.d.ts +2 -2
- package/lib/dts/prompt/prompt-builder.d.ts +10 -4
- package/lib/dts/prompt/template.d.ts +3 -3
- package/lib/dts/utils/logger.d.ts +33 -8
- package/lib/dts/utils/model-utils.d.ts +1 -1
- package/lib/dts/utils/stream-utils.d.ts +3 -1
- package/lib/dts/utils/type-utils.d.ts +7 -2
- package/lib/esm/agents/agent.d.ts +168 -29
- package/lib/esm/agents/agent.js +152 -56
- package/lib/esm/agents/ai-agent.d.ts +7 -7
- package/lib/esm/agents/ai-agent.js +18 -14
- package/lib/{dts/models → esm/agents}/chat-model.d.ts +29 -19
- package/lib/esm/{models → agents}/chat-model.js +56 -15
- package/lib/esm/agents/guide-rail-agent.d.ts +62 -0
- package/lib/esm/agents/guide-rail-agent.js +11 -0
- package/lib/esm/agents/mcp-agent.d.ts +3 -4
- package/lib/esm/agents/mcp-agent.js +11 -11
- package/lib/esm/agents/team-agent.d.ts +7 -8
- package/lib/esm/agents/team-agent.js +10 -10
- package/lib/esm/agents/user-agent.d.ts +4 -4
- package/lib/esm/agents/user-agent.js +10 -10
- package/lib/esm/aigne/aigne.d.ts +13 -11
- package/lib/esm/aigne/aigne.js +7 -6
- package/lib/esm/aigne/context.d.ts +19 -8
- package/lib/esm/aigne/context.js +28 -8
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/loader/agent-yaml.d.ts +2 -2
- package/lib/esm/loader/index.d.ts +18 -11
- package/lib/esm/loader/index.js +8 -27
- package/lib/esm/memory/default-memory/default-memory-storage/index.d.ts +30 -0
- package/lib/esm/memory/default-memory/default-memory-storage/index.js +64 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.d.ts +7 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrate.js +16 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.d.ts +7 -0
- package/lib/esm/memory/default-memory/default-memory-storage/migrations/20250523165801-init.js +28 -0
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.d.ts +10 -0
- package/lib/esm/memory/default-memory/default-memory-storage/models/memory.js +29 -0
- package/lib/esm/memory/default-memory/index.d.ts +10 -0
- package/lib/esm/memory/{default-memory.js → default-memory/index.js} +15 -24
- package/lib/esm/memory/default-memory/storage.d.ts +13 -0
- package/lib/esm/memory/default-memory/storage.js +2 -0
- package/lib/esm/memory/memory.d.ts +3 -2
- package/lib/esm/memory/memory.js +2 -2
- package/lib/esm/memory/retriever.d.ts +2 -2
- package/lib/esm/prompt/prompt-builder.d.ts +10 -4
- package/lib/esm/prompt/prompt-builder.js +4 -4
- package/lib/esm/prompt/template.d.ts +3 -3
- package/lib/esm/utils/json-schema.js +1 -1
- package/lib/esm/utils/logger.d.ts +33 -8
- package/lib/esm/utils/logger.js +61 -4
- package/lib/esm/utils/model-utils.d.ts +1 -1
- package/lib/esm/utils/stream-utils.d.ts +3 -1
- package/lib/esm/utils/stream-utils.js +29 -1
- package/lib/esm/utils/type-utils.d.ts +7 -2
- package/package.json +4 -20
- package/lib/cjs/client/client.d.ts +0 -97
- package/lib/cjs/client/client.js +0 -87
- package/lib/cjs/client/index.d.ts +0 -1
- package/lib/cjs/client/index.js +0 -17
- package/lib/cjs/memory/default-memory.d.ts +0 -16
- package/lib/cjs/models/bedrock-chat-model.d.ts +0 -79
- package/lib/cjs/models/bedrock-chat-model.js +0 -303
- package/lib/cjs/models/claude-chat-model.d.ts +0 -114
- package/lib/cjs/models/claude-chat-model.js +0 -317
- package/lib/cjs/models/deepseek-chat-model.d.ts +0 -23
- package/lib/cjs/models/deepseek-chat-model.js +0 -35
- package/lib/cjs/models/gemini-chat-model.d.ts +0 -23
- package/lib/cjs/models/gemini-chat-model.js +0 -35
- package/lib/cjs/models/ollama-chat-model.d.ts +0 -22
- package/lib/cjs/models/ollama-chat-model.js +0 -34
- package/lib/cjs/models/open-router-chat-model.d.ts +0 -22
- package/lib/cjs/models/open-router-chat-model.js +0 -34
- package/lib/cjs/models/openai-chat-model.d.ts +0 -166
- package/lib/cjs/models/openai-chat-model.js +0 -415
- package/lib/cjs/models/xai-chat-model.d.ts +0 -21
- package/lib/cjs/models/xai-chat-model.js +0 -33
- package/lib/cjs/server/error.d.ts +0 -15
- package/lib/cjs/server/error.js +0 -22
- package/lib/cjs/server/index.d.ts +0 -2
- package/lib/cjs/server/index.js +0 -18
- package/lib/cjs/server/server.d.ts +0 -135
- package/lib/cjs/server/server.js +0 -187
- package/lib/dts/client/client.d.ts +0 -97
- package/lib/dts/client/index.d.ts +0 -1
- package/lib/dts/memory/default-memory.d.ts +0 -16
- package/lib/dts/models/bedrock-chat-model.d.ts +0 -79
- package/lib/dts/models/claude-chat-model.d.ts +0 -114
- package/lib/dts/models/deepseek-chat-model.d.ts +0 -23
- package/lib/dts/models/gemini-chat-model.d.ts +0 -23
- package/lib/dts/models/ollama-chat-model.d.ts +0 -22
- package/lib/dts/models/open-router-chat-model.d.ts +0 -22
- package/lib/dts/models/openai-chat-model.d.ts +0 -166
- package/lib/dts/models/xai-chat-model.d.ts +0 -21
- package/lib/dts/server/error.d.ts +0 -15
- package/lib/dts/server/index.d.ts +0 -2
- package/lib/dts/server/server.d.ts +0 -135
- package/lib/esm/client/client.d.ts +0 -97
- package/lib/esm/client/client.js +0 -83
- package/lib/esm/client/index.d.ts +0 -1
- package/lib/esm/client/index.js +0 -1
- package/lib/esm/memory/default-memory.d.ts +0 -16
- package/lib/esm/models/bedrock-chat-model.d.ts +0 -79
- package/lib/esm/models/bedrock-chat-model.js +0 -298
- package/lib/esm/models/claude-chat-model.d.ts +0 -114
- package/lib/esm/models/claude-chat-model.js +0 -310
- package/lib/esm/models/deepseek-chat-model.d.ts +0 -23
- package/lib/esm/models/deepseek-chat-model.js +0 -31
- package/lib/esm/models/gemini-chat-model.d.ts +0 -23
- package/lib/esm/models/gemini-chat-model.js +0 -31
- package/lib/esm/models/ollama-chat-model.d.ts +0 -22
- package/lib/esm/models/ollama-chat-model.js +0 -30
- package/lib/esm/models/open-router-chat-model.d.ts +0 -22
- package/lib/esm/models/open-router-chat-model.js +0 -30
- package/lib/esm/models/openai-chat-model.d.ts +0 -166
- package/lib/esm/models/openai-chat-model.js +0 -405
- package/lib/esm/models/xai-chat-model.d.ts +0 -21
- package/lib/esm/models/xai-chat-model.js +0 -29
- package/lib/esm/server/error.d.ts +0 -15
- package/lib/esm/server/error.js +0 -18
- package/lib/esm/server/index.d.ts +0 -2
- package/lib/esm/server/index.js +0 -2
- package/lib/esm/server/server.d.ts +0 -135
- package/lib/esm/server/server.js +0 -180
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatModel = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const agent_js_1 = require("
|
|
5
|
+
const agent_js_1 = require("./agent.js");
|
|
6
6
|
/**
|
|
7
7
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
8
8
|
*
|
|
@@ -12,19 +12,19 @@ const agent_js_1 = require("../agents/agent.js");
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* Here's how to implement a custom ChatModel:
|
|
15
|
-
* {@includeCode ../../test/
|
|
15
|
+
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model}
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* Here's an example showing streaming response with readable stream:
|
|
19
|
-
* {@includeCode ../../test/
|
|
19
|
+
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-streaming}
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* Here's an example showing streaming response with async generator:
|
|
23
|
-
* {@includeCode ../../test/
|
|
23
|
+
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-streaming-async-generator}
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* Here's an example with tool calls:
|
|
27
|
-
* {@includeCode ../../test/
|
|
27
|
+
* {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
|
|
28
28
|
*/
|
|
29
29
|
class ChatModel extends agent_js_1.Agent {
|
|
30
30
|
constructor() {
|
|
@@ -59,23 +59,51 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Normalizes tool names to ensure compatibility with language models
|
|
64
|
+
*
|
|
65
|
+
* This method converts tool names to a format that complies with model requirements
|
|
66
|
+
* by replacing hyphens and whitespace characters with underscores. The normalized
|
|
67
|
+
* names are used for tool calls while preserving the original names for reference.
|
|
68
|
+
*
|
|
69
|
+
* @param name - The original tool name to normalize
|
|
70
|
+
* @returns A promise that resolves to the normalized tool name
|
|
71
|
+
*/
|
|
72
|
+
async normalizeToolName(name) {
|
|
73
|
+
return name.replaceAll(/[-\s]/g, "_");
|
|
74
|
+
}
|
|
62
75
|
/**
|
|
63
76
|
* Performs preprocessing operations before handling input
|
|
64
77
|
*
|
|
65
78
|
* Primarily checks if token usage exceeds limits, throwing an exception if limits are exceeded
|
|
66
79
|
*
|
|
67
80
|
* @param input Input message
|
|
68
|
-
* @param
|
|
81
|
+
* @param options Options for invoking the agent
|
|
69
82
|
* @throws Error if token usage exceeds maximum limit
|
|
70
83
|
*/
|
|
71
|
-
preprocess(input,
|
|
72
|
-
super.preprocess(input,
|
|
73
|
-
const { limits, usage } = context;
|
|
84
|
+
async preprocess(input, options) {
|
|
85
|
+
super.preprocess(input, options);
|
|
86
|
+
const { limits, usage } = options.context;
|
|
74
87
|
const usedTokens = usage.outputTokens + usage.inputTokens;
|
|
75
88
|
if (limits?.maxTokens && usedTokens >= limits.maxTokens) {
|
|
76
89
|
throw new Error(`Exceeded max tokens ${usedTokens}/${limits.maxTokens}`);
|
|
77
90
|
}
|
|
78
|
-
|
|
91
|
+
// Automatically convert tool names to a valid format
|
|
92
|
+
if (input.tools?.length) {
|
|
93
|
+
const toolsMap = {};
|
|
94
|
+
const tools = [];
|
|
95
|
+
for (const originalTool of input.tools) {
|
|
96
|
+
const name = await this.normalizeToolName(originalTool.function.name);
|
|
97
|
+
const tool = {
|
|
98
|
+
...originalTool,
|
|
99
|
+
function: { ...originalTool.function, name },
|
|
100
|
+
};
|
|
101
|
+
tools.push(tool);
|
|
102
|
+
toolsMap[name] = originalTool;
|
|
103
|
+
}
|
|
104
|
+
this.validateToolNames(tools);
|
|
105
|
+
Object.assign(input, { _toolsMap: toolsMap, tools });
|
|
106
|
+
}
|
|
79
107
|
}
|
|
80
108
|
/**
|
|
81
109
|
* Performs postprocessing operations after handling output
|
|
@@ -84,14 +112,27 @@ class ChatModel extends agent_js_1.Agent {
|
|
|
84
112
|
*
|
|
85
113
|
* @param input Input message
|
|
86
114
|
* @param output Output message
|
|
87
|
-
* @param
|
|
115
|
+
* @param options Options for invoking the agent
|
|
88
116
|
*/
|
|
89
|
-
postprocess(input, output,
|
|
90
|
-
|
|
117
|
+
async postprocess(input, output, options) {
|
|
118
|
+
// Restore original tool names in the output
|
|
119
|
+
if (output.toolCalls?.length) {
|
|
120
|
+
const toolsMap = input._toolsMap;
|
|
121
|
+
if (toolsMap) {
|
|
122
|
+
for (const toolCall of output.toolCalls) {
|
|
123
|
+
const originalTool = toolsMap[toolCall.function.name];
|
|
124
|
+
if (!originalTool) {
|
|
125
|
+
throw new Error(`Tool "${toolCall.function.name}" not found in tools map`);
|
|
126
|
+
}
|
|
127
|
+
toolCall.function.name = originalTool.function.name;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
super.postprocess(input, output, options);
|
|
91
132
|
const { usage } = output;
|
|
92
133
|
if (usage) {
|
|
93
|
-
context.usage.outputTokens += usage.outputTokens;
|
|
94
|
-
context.usage.inputTokens += usage.inputTokens;
|
|
134
|
+
options.context.usage.outputTokens += usage.outputTokens;
|
|
135
|
+
options.context.usage.inputTokens += usage.inputTokens;
|
|
95
136
|
}
|
|
96
137
|
}
|
|
97
138
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Agent, AgentOptions, Message } from "./agent.js";
|
|
2
|
+
/**
|
|
3
|
+
* Input interface for GuideRail agents
|
|
4
|
+
*
|
|
5
|
+
* GuideRail agents receive both input and expected output, allowing them to
|
|
6
|
+
* validate, transform, or control the flow of messages between other agents.
|
|
7
|
+
*/
|
|
8
|
+
export interface GuideRailAgentInput extends Message {
|
|
9
|
+
/**
|
|
10
|
+
* The input data to be processed
|
|
11
|
+
*
|
|
12
|
+
* This is the original message that would be sent to the target agent
|
|
13
|
+
*/
|
|
14
|
+
input?: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* The expected output data
|
|
17
|
+
*
|
|
18
|
+
* This is what the target agent is expected to produce, allowing
|
|
19
|
+
* the GuideRail agent to validate or transform the data flow
|
|
20
|
+
*/
|
|
21
|
+
output?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Output interface for GuideRail agents
|
|
25
|
+
*
|
|
26
|
+
* GuideRail agents can either allow the process to continue or abort it with a reason.
|
|
27
|
+
* This provides a mechanism for enforcing rules, validating data, and controlling
|
|
28
|
+
* the execution flow of the agent system.
|
|
29
|
+
*/
|
|
30
|
+
export interface GuideRailAgentOutput extends Message {
|
|
31
|
+
/**
|
|
32
|
+
* Whether to abort the current process
|
|
33
|
+
*
|
|
34
|
+
* When true, the agent system should stop the current execution flow
|
|
35
|
+
* and prevent further processing based on this input/output pair
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
abort?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Reason for aborting the process
|
|
42
|
+
*
|
|
43
|
+
* When abort is true, this provides a human-readable explanation
|
|
44
|
+
* for why the process was stopped
|
|
45
|
+
*/
|
|
46
|
+
reason?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* GuideRail agent type definition
|
|
50
|
+
*
|
|
51
|
+
* GuideRail agents act as validators, transformers, or controllers for the message
|
|
52
|
+
* flow between agents. They can enforce rules, perform safety checks, ensure data
|
|
53
|
+
* quality, or implement business logic validations.
|
|
54
|
+
*
|
|
55
|
+
* Use GuideRail agents when you need to:
|
|
56
|
+
* - Validate inputs or outputs against specific criteria
|
|
57
|
+
* - Enforce security or safety policies
|
|
58
|
+
* - Implement business rules that control agent interactions
|
|
59
|
+
* - Monitor and audit agent behavior
|
|
60
|
+
*/
|
|
61
|
+
export type GuideRailAgent = Agent<GuideRailAgentInput, GuideRailAgentOutput>;
|
|
62
|
+
export declare const guideRailAgentOptions: AgentOptions<GuideRailAgentInput, GuideRailAgentOutput>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.guideRailAgentOptions = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.guideRailAgentOptions = {
|
|
6
|
+
inputSchema: zod_1.z.object({
|
|
7
|
+
input: zod_1.z.unknown(),
|
|
8
|
+
output: zod_1.z.unknown(),
|
|
9
|
+
}),
|
|
10
|
+
outputSchema: zod_1.z.object({
|
|
11
|
+
abort: zod_1.z.boolean().optional().describe("Whether to abort the current process"),
|
|
12
|
+
reason: zod_1.z.string().optional().describe("Reason for aborting the process"),
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
@@ -6,9 +6,8 @@ import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.j
|
|
|
6
6
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
7
7
|
import type { CallToolResult, GetPromptResult, Implementation, ReadResourceResult, Request } from "@modelcontextprotocol/sdk/types.js";
|
|
8
8
|
import { type ZodType, z } from "zod";
|
|
9
|
-
import type { Context } from "../aigne/context.js";
|
|
10
9
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
11
|
-
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
10
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
|
|
12
11
|
export interface MCPAgentOptions extends AgentOptions {
|
|
13
12
|
client: Client;
|
|
14
13
|
prompts?: MCPPrompt[];
|
|
@@ -150,10 +149,10 @@ export declare class MCPAgent extends Agent {
|
|
|
150
149
|
* throws an error if called.
|
|
151
150
|
*
|
|
152
151
|
* @param _input Input message (unused)
|
|
153
|
-
* @param
|
|
152
|
+
* @param _options AgentInvokeOptions (unused)
|
|
154
153
|
* @throws Error This method always throws an error since MCPAgent is not directly invokable
|
|
155
154
|
*/
|
|
156
|
-
process(_input: Message,
|
|
155
|
+
process(_input: Message, _options: AgentInvokeOptions): Promise<Message>;
|
|
157
156
|
/**
|
|
158
157
|
* Shut down the agent and close the MCP connection.
|
|
159
158
|
*
|
|
@@ -84,25 +84,25 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
84
84
|
version: MCP_AGENT_CLIENT_VERSION,
|
|
85
85
|
}, undefined, isSSEServerParameters(options) ? { transportCreator, ...options } : undefined);
|
|
86
86
|
const transport = transportCreator();
|
|
87
|
-
logger_js_1.logger.
|
|
87
|
+
logger_js_1.logger.debug(`Connecting to MCP server: ${getMCPServerString(options)}`);
|
|
88
88
|
await client.connect(transport);
|
|
89
89
|
const mcpServer = getMCPServerName(client);
|
|
90
90
|
const { tools: isToolsAvailable, prompts: isPromptsAvailable, resources: isResourcesAvailable, } = client.getServerCapabilities() ?? {};
|
|
91
|
-
logger_js_1.logger.
|
|
91
|
+
logger_js_1.logger.debug(`Listing tools from ${mcpServer}`);
|
|
92
92
|
const skills = isToolsAvailable
|
|
93
93
|
? await client.listTools().then(({ tools }) => {
|
|
94
|
-
logger_js_1.logger.
|
|
94
|
+
logger_js_1.logger.debug(`Listing tools from ${mcpServer} completed %O`, tools?.map((i) => i.name));
|
|
95
95
|
return tools.map((tool) => (0, mcp_utils_js_1.toolFromMCPTool)(tool, { client }));
|
|
96
96
|
})
|
|
97
97
|
: undefined;
|
|
98
|
-
logger_js_1.logger.
|
|
98
|
+
logger_js_1.logger.debug(`Listing prompts from ${mcpServer}`);
|
|
99
99
|
const prompts = isPromptsAvailable
|
|
100
100
|
? await client.listPrompts().then(({ prompts }) => {
|
|
101
|
-
logger_js_1.logger.
|
|
101
|
+
logger_js_1.logger.debug(`Listing prompts from ${mcpServer} completed %O`, prompts?.map((i) => i.name));
|
|
102
102
|
return prompts.map((prompt) => (0, mcp_utils_js_1.promptFromMCPPrompt)(prompt, { client }));
|
|
103
103
|
})
|
|
104
104
|
: undefined;
|
|
105
|
-
logger_js_1.logger.
|
|
105
|
+
logger_js_1.logger.debug(`Listing resources from ${mcpServer}`);
|
|
106
106
|
// TODO: should conditionally call listResourceTemplates based on the server capabilities
|
|
107
107
|
// but the capability is not correct in the current SDK version
|
|
108
108
|
const resources = isResourcesAvailable
|
|
@@ -111,7 +111,7 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
111
111
|
client.listResourceTemplates().catch(() => ({ resourceTemplates: [] })),
|
|
112
112
|
]).then(([{ resources }, { resourceTemplates }]) => {
|
|
113
113
|
const result = [...resources, ...resourceTemplates].map((resource) => (0, mcp_utils_js_1.resourceFromMCPResource)(resource, { client }));
|
|
114
|
-
logger_js_1.logger.
|
|
114
|
+
logger_js_1.logger.debug(`Listing resources from ${mcpServer} completed %O`, result.map((i) => i.name));
|
|
115
115
|
return result;
|
|
116
116
|
})
|
|
117
117
|
: undefined;
|
|
@@ -183,10 +183,10 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
183
183
|
* throws an error if called.
|
|
184
184
|
*
|
|
185
185
|
* @param _input Input message (unused)
|
|
186
|
-
* @param
|
|
186
|
+
* @param _options AgentInvokeOptions (unused)
|
|
187
187
|
* @throws Error This method always throws an error since MCPAgent is not directly invokable
|
|
188
188
|
*/
|
|
189
|
-
async process(_input,
|
|
189
|
+
async process(_input, _options) {
|
|
190
190
|
throw new Error("Method not implemented.");
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
@@ -235,7 +235,7 @@ class ClientWithReconnect extends index_js_1.Client {
|
|
|
235
235
|
}, {
|
|
236
236
|
retries: this.reconnectOptions?.maxReconnects ?? DEFAULT_MAX_RECONNECTS,
|
|
237
237
|
shouldRetry: this.shouldReconnect,
|
|
238
|
-
onFailedAttempt: (error) => logger_js_1.logger.
|
|
238
|
+
onFailedAttempt: (error) => logger_js_1.logger.error("Reconnect attempt failed: %O", error),
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
async request(request, resultSchema, options) {
|
|
@@ -248,7 +248,7 @@ class ClientWithReconnect extends index_js_1.Client {
|
|
|
248
248
|
}
|
|
249
249
|
catch (error) {
|
|
250
250
|
if (this.shouldReconnect(error)) {
|
|
251
|
-
logger_js_1.logger.
|
|
251
|
+
logger_js_1.logger.error("Error occurred, reconnecting to MCP server: %O", error);
|
|
252
252
|
await this.reconnect();
|
|
253
253
|
return await super.request(request, resultSchema, mergedOptions);
|
|
254
254
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Context } from "../aigne/context.js";
|
|
2
1
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import { Agent, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
2
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
3
|
/**
|
|
5
4
|
* Defines the processing modes available for a TeamAgent.
|
|
6
5
|
*
|
|
@@ -89,10 +88,10 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
89
88
|
* - In parallel mode: Process input through all agents simultaneously and combine their outputs
|
|
90
89
|
*
|
|
91
90
|
* @param input The message to process
|
|
92
|
-
* @param
|
|
91
|
+
* @param options The invocation options
|
|
93
92
|
* @returns A stream of message chunks that collectively form the response
|
|
94
93
|
*/
|
|
95
|
-
process(input: I,
|
|
94
|
+
process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
96
95
|
/**
|
|
97
96
|
* Process input sequentially through each agent in the team.
|
|
98
97
|
*
|
|
@@ -103,12 +102,12 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
103
102
|
* 4. Updates the team's agent list with any changes that occurred during processing
|
|
104
103
|
*
|
|
105
104
|
* @param input The message to process
|
|
106
|
-
* @param
|
|
105
|
+
* @param options The invocation options
|
|
107
106
|
* @returns A stream of message chunks from all agents
|
|
108
107
|
*
|
|
109
108
|
* @private
|
|
110
109
|
*/
|
|
111
|
-
_processSequential(input: I,
|
|
110
|
+
_processSequential(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
112
111
|
/**
|
|
113
112
|
* Process input in parallel through all agents in the team.
|
|
114
113
|
*
|
|
@@ -118,10 +117,10 @@ export declare class TeamAgent<I extends Message, O extends Message> extends Age
|
|
|
118
117
|
* 3. Updates the team's agent list with any changes that occurred during processing
|
|
119
118
|
*
|
|
120
119
|
* @param input The message to process
|
|
121
|
-
* @param
|
|
120
|
+
* @param options The invocation options
|
|
122
121
|
* @returns A stream of combined message chunks from all agents
|
|
123
122
|
*
|
|
124
123
|
* @private
|
|
125
124
|
*/
|
|
126
|
-
_processParallel(input: I,
|
|
125
|
+
_processParallel(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
127
126
|
}
|
|
@@ -86,15 +86,15 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
86
86
|
* - In parallel mode: Process input through all agents simultaneously and combine their outputs
|
|
87
87
|
*
|
|
88
88
|
* @param input The message to process
|
|
89
|
-
* @param
|
|
89
|
+
* @param options The invocation options
|
|
90
90
|
* @returns A stream of message chunks that collectively form the response
|
|
91
91
|
*/
|
|
92
|
-
process(input,
|
|
92
|
+
process(input, options) {
|
|
93
93
|
switch (this.mode) {
|
|
94
94
|
case ProcessMode.sequential:
|
|
95
|
-
return this._processSequential(input,
|
|
95
|
+
return this._processSequential(input, options);
|
|
96
96
|
case ProcessMode.parallel:
|
|
97
|
-
return this._processParallel(input,
|
|
97
|
+
return this._processParallel(input, options);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -107,18 +107,18 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
107
107
|
* 4. Updates the team's agent list with any changes that occurred during processing
|
|
108
108
|
*
|
|
109
109
|
* @param input The message to process
|
|
110
|
-
* @param
|
|
110
|
+
* @param options The invocation options
|
|
111
111
|
* @returns A stream of message chunks from all agents
|
|
112
112
|
*
|
|
113
113
|
* @private
|
|
114
114
|
*/
|
|
115
|
-
async *_processSequential(input,
|
|
115
|
+
async *_processSequential(input, options) {
|
|
116
116
|
const output = {};
|
|
117
117
|
// Clone the agents to run, so that we can update the agents list during the loop
|
|
118
118
|
const agents = [...this.skills];
|
|
119
119
|
const newAgents = [];
|
|
120
120
|
for (const agent of agents) {
|
|
121
|
-
const [o, transferToAgent] = await context.invoke(agent, { ...input, ...output }, { returnActiveAgent: true, streaming: true });
|
|
121
|
+
const [o, transferToAgent] = await options.context.invoke(agent, { ...input, ...output }, { returnActiveAgent: true, streaming: true });
|
|
122
122
|
for await (const chunk of o) {
|
|
123
123
|
yield chunk;
|
|
124
124
|
(0, stream_utils_js_1.mergeAgentResponseChunk)(output, chunk);
|
|
@@ -137,13 +137,13 @@ class TeamAgent extends agent_js_1.Agent {
|
|
|
137
137
|
* 3. Updates the team's agent list with any changes that occurred during processing
|
|
138
138
|
*
|
|
139
139
|
* @param input The message to process
|
|
140
|
-
* @param
|
|
140
|
+
* @param options The invocation options
|
|
141
141
|
* @returns A stream of combined message chunks from all agents
|
|
142
142
|
*
|
|
143
143
|
* @private
|
|
144
144
|
*/
|
|
145
|
-
async *_processParallel(input,
|
|
146
|
-
const result = await Promise.all(this.skills.map((agent) => context.invoke(agent, input, { returnActiveAgent: true, streaming: true })));
|
|
145
|
+
async *_processParallel(input, options) {
|
|
146
|
+
const result = await Promise.all(this.skills.map((agent) => options.context.invoke(agent, input, { returnActiveAgent: true, streaming: true })));
|
|
147
147
|
const streams = result.map((i) => i[0]);
|
|
148
148
|
const read = async (index, reader) => {
|
|
149
149
|
const promise = reader.read();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReadableStream } from "node:stream/web";
|
|
2
2
|
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import { type MessagePayload } from "../aigne/message-queue.js";
|
|
4
|
-
import { Agent, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "./agent.js";
|
|
4
|
+
import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "./agent.js";
|
|
5
5
|
export interface UserAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
6
6
|
context: Context;
|
|
7
7
|
process?: FunctionAgentFn<I, O>;
|
|
@@ -14,14 +14,14 @@ export declare class UserAgent<I extends Message = Message, O extends Message =
|
|
|
14
14
|
private _process?;
|
|
15
15
|
private activeAgent?;
|
|
16
16
|
protected subscribeToTopics(context: Pick<Context, "subscribe">): void;
|
|
17
|
-
protected publishToTopics(output: O,
|
|
17
|
+
protected publishToTopics(output: O, options: AgentInvokeOptions): Promise<void>;
|
|
18
18
|
invoke: Agent<I, O>["invoke"];
|
|
19
|
-
process(input: I,
|
|
19
|
+
process(input: I, options: AgentInvokeOptions): Promise<AgentProcessResult<O>>;
|
|
20
20
|
publish: Context["publish"];
|
|
21
21
|
subscribe: Context["subscribe"];
|
|
22
22
|
unsubscribe: Context["unsubscribe"];
|
|
23
23
|
get stream(): ReadableStream<MessagePayload & {
|
|
24
24
|
topic: string;
|
|
25
25
|
}>;
|
|
26
|
-
protected checkAgentInvokesUsage(
|
|
26
|
+
protected checkAgentInvokesUsage(_options: AgentInvokeOptions): void;
|
|
27
27
|
}
|
|
@@ -22,21 +22,21 @@ class UserAgent extends agent_js_1.Agent {
|
|
|
22
22
|
if (this._process)
|
|
23
23
|
super.subscribeToTopics(context);
|
|
24
24
|
}
|
|
25
|
-
async publishToTopics(output,
|
|
25
|
+
async publishToTopics(output, options) {
|
|
26
26
|
if (this._process)
|
|
27
|
-
super.publishToTopics(output,
|
|
27
|
+
super.publishToTopics(output, options);
|
|
28
28
|
}
|
|
29
|
-
invoke = ((input,
|
|
30
|
-
if (!context)
|
|
29
|
+
invoke = ((input, options = {}) => {
|
|
30
|
+
if (!options.context)
|
|
31
31
|
this.context = this.context.newContext({ reset: true });
|
|
32
|
-
return super.invoke(input, context
|
|
32
|
+
return super.invoke(input, { ...options, context: this.context });
|
|
33
33
|
});
|
|
34
|
-
async process(input,
|
|
34
|
+
async process(input, options) {
|
|
35
35
|
if (this._process) {
|
|
36
|
-
return this._process(input,
|
|
36
|
+
return this._process(input, options);
|
|
37
37
|
}
|
|
38
38
|
if (this.activeAgent) {
|
|
39
|
-
const [output, agent] = await context.invoke(this.activeAgent, input, {
|
|
39
|
+
const [output, agent] = await options.context.invoke(this.activeAgent, input, {
|
|
40
40
|
returnActiveAgent: true,
|
|
41
41
|
streaming: true,
|
|
42
42
|
});
|
|
@@ -47,7 +47,7 @@ class UserAgent extends agent_js_1.Agent {
|
|
|
47
47
|
}
|
|
48
48
|
const publicTopic = typeof this.publishTopic === "function" ? await this.publishTopic(input) : this.publishTopic;
|
|
49
49
|
if (publicTopic?.length) {
|
|
50
|
-
context.publish(publicTopic, input);
|
|
50
|
+
options.context.publish(publicTopic, input);
|
|
51
51
|
if (this.subscribeTopic) {
|
|
52
52
|
return this.subscribe(this.subscribeTopic).then((res) => res.message);
|
|
53
53
|
}
|
|
@@ -80,7 +80,7 @@ class UserAgent extends agent_js_1.Agent {
|
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
checkAgentInvokesUsage(
|
|
83
|
+
checkAgentInvokesUsage(_options) {
|
|
84
84
|
// ignore calls usage check for UserAgent
|
|
85
85
|
}
|
|
86
86
|
}
|
package/lib/cjs/aigne/aigne.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
|
|
2
|
+
import { ChatModel } from "../agents/chat-model.js";
|
|
2
3
|
import type { UserAgent } from "../agents/user-agent.js";
|
|
3
|
-
import {
|
|
4
|
-
import { AIGNEContext, type InvokeOptions } from "./context.js";
|
|
4
|
+
import { type LoadOptions } from "../loader/index.js";
|
|
5
|
+
import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
|
|
5
6
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
6
7
|
import type { ContextLimits } from "./usage.js";
|
|
7
8
|
/**
|
|
@@ -45,7 +46,7 @@ export interface AIGNEOptions {
|
|
|
45
46
|
* Here's an example of how to use AIGNE with streaming response:
|
|
46
47
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
47
48
|
*/
|
|
48
|
-
export declare class AIGNE {
|
|
49
|
+
export declare class AIGNE<U extends UserContext = UserContext> {
|
|
49
50
|
/**
|
|
50
51
|
* Loads an AIGNE instance from a directory containing an aigne.yaml file and agent definitions.
|
|
51
52
|
* This static method provides a convenient way to initialize an AIGNE system from configuration files.
|
|
@@ -54,7 +55,7 @@ export declare class AIGNE {
|
|
|
54
55
|
* @param options - Options to override the loaded configuration.
|
|
55
56
|
* @returns A fully initialized AIGNE instance with configured agents and skills.
|
|
56
57
|
*/
|
|
57
|
-
static load(path: string, options
|
|
58
|
+
static load(path: string, options: AIGNEOptions & Pick<LoadOptions, "models">): Promise<AIGNE>;
|
|
58
59
|
/**
|
|
59
60
|
* Creates a new AIGNE instance with the specified options.
|
|
60
61
|
*
|
|
@@ -110,7 +111,7 @@ export declare class AIGNE {
|
|
|
110
111
|
*
|
|
111
112
|
* @returns A new AIGNEContext instance bound to this AIGNE.
|
|
112
113
|
*/
|
|
113
|
-
newContext(): AIGNEContext;
|
|
114
|
+
newContext(options?: Partial<Context>): AIGNEContext;
|
|
114
115
|
/**
|
|
115
116
|
* Creates a user agent for consistent interactions with a specified agent.
|
|
116
117
|
* This method allows you to create a wrapper around an agent for repeated invocations.
|
|
@@ -133,7 +134,7 @@ export declare class AIGNE {
|
|
|
133
134
|
* @param options.streaming - Must be false to return a response stream
|
|
134
135
|
* @returns A promise resolving to a tuple containing the agent's response and the final active agent
|
|
135
136
|
*/
|
|
136
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
137
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
137
138
|
returnActiveAgent: true;
|
|
138
139
|
streaming?: false;
|
|
139
140
|
}): Promise<[O, Agent]>;
|
|
@@ -147,7 +148,7 @@ export declare class AIGNE {
|
|
|
147
148
|
* @param options.streaming - Must be true to return a response stream
|
|
148
149
|
* @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
|
|
149
150
|
*/
|
|
150
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
151
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
151
152
|
returnActiveAgent: true;
|
|
152
153
|
streaming: true;
|
|
153
154
|
}): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
|
|
@@ -164,7 +165,7 @@ export declare class AIGNE {
|
|
|
164
165
|
* Here's a simple example of how to invoke an agent:
|
|
165
166
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
|
|
166
167
|
*/
|
|
167
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options?: InvokeOptions & {
|
|
168
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options?: InvokeOptions<U> & {
|
|
168
169
|
returnActiveAgent?: false;
|
|
169
170
|
streaming?: false;
|
|
170
171
|
}): Promise<O>;
|
|
@@ -181,7 +182,7 @@ export declare class AIGNE {
|
|
|
181
182
|
* Here's an example of how to invoke an agent with streaming response:
|
|
182
183
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
|
|
183
184
|
*/
|
|
184
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions & {
|
|
185
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I | string, options: InvokeOptions<U> & {
|
|
185
186
|
returnActiveAgent?: false;
|
|
186
187
|
streaming: true;
|
|
187
188
|
}): Promise<AgentResponseStream<O>>;
|
|
@@ -195,7 +196,7 @@ export declare class AIGNE {
|
|
|
195
196
|
* @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
|
|
196
197
|
* with optional active agent information based on the provided options
|
|
197
198
|
*/
|
|
198
|
-
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I | string, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
|
+
invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I | string, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
|
|
199
200
|
/**
|
|
200
201
|
* Publishes a message to the message queue for inter-agent communication.
|
|
201
202
|
* This method broadcasts a message to all subscribers of the specified topic(s).
|
|
@@ -203,12 +204,13 @@ export declare class AIGNE {
|
|
|
203
204
|
*
|
|
204
205
|
* @param topic - The topic or array of topics to publish the message to
|
|
205
206
|
* @param payload - The message payload to be delivered to subscribers
|
|
207
|
+
* @param options - Optional configuration parameters for the publish operation
|
|
206
208
|
*
|
|
207
209
|
* @example
|
|
208
210
|
* Here's an example of how to publish a message:
|
|
209
211
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
|
|
210
212
|
*/
|
|
211
|
-
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string): void;
|
|
213
|
+
publish(topic: string | string[], payload: Omit<MessagePayload, "context"> | Message | string, options?: InvokeOptions<U>): void;
|
|
212
214
|
/**
|
|
213
215
|
* Subscribes to receive the next message on a specific topic.
|
|
214
216
|
* This overload returns a Promise that resolves with the next message published to the topic.
|
package/lib/cjs/aigne/aigne.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AIGNE = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const agent_js_1 = require("../agents/agent.js");
|
|
6
|
+
const chat_model_js_1 = require("../agents/chat-model.js");
|
|
6
7
|
const index_js_1 = require("../loader/index.js");
|
|
7
|
-
const chat_model_js_1 = require("../models/chat-model.js");
|
|
8
8
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
9
9
|
const context_js_1 = require("./context.js");
|
|
10
10
|
const message_queue_js_1 = require("./message-queue.js");
|
|
@@ -30,7 +30,7 @@ class AIGNE {
|
|
|
30
30
|
* @returns A fully initialized AIGNE instance with configured agents and skills.
|
|
31
31
|
*/
|
|
32
32
|
static async load(path, options) {
|
|
33
|
-
const { model, agents, skills, ...aigne } = await (0, index_js_1.load)({ path });
|
|
33
|
+
const { model, agents, skills, ...aigne } = await (0, index_js_1.load)({ models: options.models, path });
|
|
34
34
|
return new AIGNE({
|
|
35
35
|
...options,
|
|
36
36
|
model: options?.model || model,
|
|
@@ -109,8 +109,8 @@ class AIGNE {
|
|
|
109
109
|
*
|
|
110
110
|
* @returns A new AIGNEContext instance bound to this AIGNE.
|
|
111
111
|
*/
|
|
112
|
-
newContext() {
|
|
113
|
-
return new context_js_1.AIGNEContext(this);
|
|
112
|
+
newContext(options) {
|
|
113
|
+
return new context_js_1.AIGNEContext(this, options);
|
|
114
114
|
}
|
|
115
115
|
invoke(agent, message, options) {
|
|
116
116
|
return new context_js_1.AIGNEContext(this).invoke(agent, message, options);
|
|
@@ -122,13 +122,14 @@ class AIGNE {
|
|
|
122
122
|
*
|
|
123
123
|
* @param topic - The topic or array of topics to publish the message to
|
|
124
124
|
* @param payload - The message payload to be delivered to subscribers
|
|
125
|
+
* @param options - Optional configuration parameters for the publish operation
|
|
125
126
|
*
|
|
126
127
|
* @example
|
|
127
128
|
* Here's an example of how to publish a message:
|
|
128
129
|
* {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}
|
|
129
130
|
*/
|
|
130
|
-
publish(topic, payload) {
|
|
131
|
-
return new context_js_1.AIGNEContext(this).publish(topic, payload);
|
|
131
|
+
publish(topic, payload, options) {
|
|
132
|
+
return new context_js_1.AIGNEContext(this).publish(topic, payload, options);
|
|
132
133
|
}
|
|
133
134
|
subscribe(topic, listener) {
|
|
134
135
|
return this.messageQueue.subscribe(topic, listener);
|