@aigne/core 1.13.0 → 1.14.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 +15 -0
- package/README.md +13 -26
- package/README.zh.md +24 -37
- package/lib/cjs/agents/agent.d.ts +522 -15
- package/lib/cjs/agents/agent.js +357 -36
- package/lib/cjs/agents/ai-agent.d.ts +210 -52
- package/lib/cjs/agents/ai-agent.js +182 -24
- package/lib/cjs/agents/mcp-agent.d.ts +112 -0
- package/lib/cjs/agents/mcp-agent.js +79 -1
- package/lib/cjs/agents/team-agent.d.ts +99 -0
- package/lib/cjs/agents/team-agent.js +94 -0
- package/lib/cjs/agents/user-agent.d.ts +6 -4
- package/lib/cjs/agents/user-agent.js +16 -5
- package/lib/cjs/aigne/aigne.d.ts +263 -16
- package/lib/cjs/aigne/aigne.js +130 -20
- package/lib/cjs/aigne/context.d.ts +24 -8
- package/lib/cjs/aigne/context.js +8 -22
- package/lib/cjs/aigne/message-queue.d.ts +26 -4
- package/lib/cjs/aigne/message-queue.js +42 -7
- package/lib/cjs/aigne/usage.d.ts +9 -0
- package/lib/cjs/aigne/usage.js +3 -0
- package/lib/cjs/client/client.d.ts +81 -3
- package/lib/cjs/client/client.js +38 -0
- package/lib/cjs/client/index.d.ts +1 -0
- package/lib/cjs/client/index.js +17 -0
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/loader/agent-js.d.ts +1 -1
- package/lib/cjs/loader/agent-js.js +2 -2
- package/lib/cjs/loader/agent-yaml.d.ts +3 -2
- package/lib/cjs/loader/agent-yaml.js +2 -1
- package/lib/cjs/loader/index.d.ts +4 -4
- package/lib/cjs/memory/default-memory.d.ts +16 -0
- package/lib/cjs/memory/default-memory.js +70 -0
- package/lib/cjs/memory/index.d.ts +3 -0
- package/lib/cjs/memory/index.js +19 -0
- package/lib/cjs/memory/memory.d.ts +89 -0
- package/lib/cjs/memory/memory.js +132 -0
- package/lib/cjs/memory/recorder.d.ts +86 -0
- package/lib/cjs/memory/recorder.js +50 -0
- package/lib/cjs/memory/retriever.d.ts +99 -0
- package/lib/cjs/memory/retriever.js +51 -0
- package/lib/cjs/models/bedrock-chat-model.d.ts +12 -3
- package/lib/cjs/models/bedrock-chat-model.js +54 -24
- package/lib/cjs/models/chat-model.d.ts +278 -1
- package/lib/cjs/models/chat-model.js +54 -0
- package/lib/cjs/models/claude-chat-model.d.ts +49 -3
- package/lib/cjs/models/claude-chat-model.js +34 -2
- package/lib/cjs/models/deepseek-chat-model.d.ts +16 -0
- package/lib/cjs/models/deepseek-chat-model.js +16 -0
- package/lib/cjs/models/gemini-chat-model.d.ts +14 -0
- package/lib/cjs/models/gemini-chat-model.js +14 -0
- package/lib/cjs/models/ollama-chat-model.d.ts +16 -0
- package/lib/cjs/models/ollama-chat-model.js +16 -0
- package/lib/cjs/models/open-router-chat-model.d.ts +16 -0
- package/lib/cjs/models/open-router-chat-model.js +16 -0
- package/lib/cjs/models/openai-chat-model.d.ts +67 -3
- package/lib/cjs/models/openai-chat-model.js +47 -2
- package/lib/cjs/models/xai-chat-model.d.ts +16 -0
- package/lib/cjs/models/xai-chat-model.js +16 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +4 -4
- package/lib/cjs/prompt/prompt-builder.js +19 -18
- package/lib/cjs/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/cjs/prompt/prompts/memory-message-template.js +10 -0
- package/lib/cjs/prompt/template.js +5 -1
- package/lib/cjs/server/error.d.ts +11 -0
- package/lib/cjs/server/error.js +11 -0
- package/lib/cjs/server/index.d.ts +2 -0
- package/lib/cjs/server/index.js +18 -0
- package/lib/cjs/server/server.d.ts +89 -8
- package/lib/cjs/server/server.js +58 -0
- package/lib/cjs/utils/fs.d.ts +2 -0
- package/lib/cjs/utils/fs.js +25 -0
- package/lib/cjs/utils/prompts.d.ts +1 -0
- package/lib/cjs/utils/prompts.js +11 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/utils/type-utils.js +14 -0
- package/lib/dts/agents/agent.d.ts +522 -15
- package/lib/dts/agents/ai-agent.d.ts +210 -52
- package/lib/dts/agents/mcp-agent.d.ts +112 -0
- package/lib/dts/agents/team-agent.d.ts +99 -0
- package/lib/dts/agents/user-agent.d.ts +6 -4
- package/lib/dts/aigne/aigne.d.ts +263 -16
- package/lib/dts/aigne/context.d.ts +24 -8
- package/lib/dts/aigne/message-queue.d.ts +26 -4
- package/lib/dts/aigne/usage.d.ts +9 -0
- package/lib/dts/client/client.d.ts +81 -3
- package/lib/dts/client/index.d.ts +1 -0
- package/lib/dts/index.d.ts +0 -1
- package/lib/dts/loader/agent-js.d.ts +1 -1
- package/lib/dts/loader/agent-yaml.d.ts +3 -2
- package/lib/dts/loader/index.d.ts +4 -4
- package/lib/dts/memory/default-memory.d.ts +16 -0
- package/lib/dts/memory/index.d.ts +3 -0
- package/lib/dts/memory/memory.d.ts +89 -0
- package/lib/dts/memory/recorder.d.ts +86 -0
- package/lib/dts/memory/retriever.d.ts +99 -0
- package/lib/dts/models/bedrock-chat-model.d.ts +12 -3
- package/lib/dts/models/chat-model.d.ts +278 -1
- package/lib/dts/models/claude-chat-model.d.ts +49 -3
- package/lib/dts/models/deepseek-chat-model.d.ts +16 -0
- package/lib/dts/models/gemini-chat-model.d.ts +14 -0
- package/lib/dts/models/ollama-chat-model.d.ts +16 -0
- package/lib/dts/models/open-router-chat-model.d.ts +16 -0
- package/lib/dts/models/openai-chat-model.d.ts +67 -3
- package/lib/dts/models/xai-chat-model.d.ts +16 -0
- package/lib/dts/prompt/prompt-builder.d.ts +4 -4
- package/lib/dts/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/dts/server/error.d.ts +11 -0
- package/lib/dts/server/index.d.ts +2 -0
- package/lib/dts/server/server.d.ts +89 -8
- package/lib/dts/utils/fs.d.ts +2 -0
- package/lib/dts/utils/prompts.d.ts +1 -0
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agents/agent.d.ts +522 -15
- package/lib/esm/agents/agent.js +351 -35
- package/lib/esm/agents/ai-agent.d.ts +210 -52
- package/lib/esm/agents/ai-agent.js +183 -25
- package/lib/esm/agents/mcp-agent.d.ts +112 -0
- package/lib/esm/agents/mcp-agent.js +79 -1
- package/lib/esm/agents/team-agent.d.ts +99 -0
- package/lib/esm/agents/team-agent.js +94 -0
- package/lib/esm/agents/user-agent.d.ts +6 -4
- package/lib/esm/agents/user-agent.js +17 -6
- package/lib/esm/aigne/aigne.d.ts +263 -16
- package/lib/esm/aigne/aigne.js +132 -22
- package/lib/esm/aigne/context.d.ts +24 -8
- package/lib/esm/aigne/context.js +9 -22
- package/lib/esm/aigne/message-queue.d.ts +26 -4
- package/lib/esm/aigne/message-queue.js +42 -8
- package/lib/esm/aigne/usage.d.ts +9 -0
- package/lib/esm/aigne/usage.js +3 -0
- package/lib/esm/client/client.d.ts +81 -3
- package/lib/esm/client/client.js +38 -0
- package/lib/esm/client/index.d.ts +1 -0
- package/lib/esm/client/index.js +1 -0
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/loader/agent-js.d.ts +1 -1
- package/lib/esm/loader/agent-js.js +2 -2
- package/lib/esm/loader/agent-yaml.d.ts +3 -2
- package/lib/esm/loader/agent-yaml.js +2 -1
- package/lib/esm/loader/index.d.ts +4 -4
- package/lib/esm/memory/default-memory.d.ts +16 -0
- package/lib/esm/memory/default-memory.js +63 -0
- package/lib/esm/memory/index.d.ts +3 -0
- package/lib/esm/memory/index.js +3 -0
- package/lib/esm/memory/memory.d.ts +89 -0
- package/lib/esm/memory/memory.js +127 -0
- package/lib/esm/memory/recorder.d.ts +86 -0
- package/lib/esm/memory/recorder.js +46 -0
- package/lib/esm/memory/retriever.d.ts +99 -0
- package/lib/esm/memory/retriever.js +47 -0
- package/lib/esm/models/bedrock-chat-model.d.ts +12 -3
- package/lib/esm/models/bedrock-chat-model.js +56 -26
- package/lib/esm/models/chat-model.d.ts +278 -1
- package/lib/esm/models/chat-model.js +54 -0
- package/lib/esm/models/claude-chat-model.d.ts +49 -3
- package/lib/esm/models/claude-chat-model.js +35 -3
- package/lib/esm/models/deepseek-chat-model.d.ts +16 -0
- package/lib/esm/models/deepseek-chat-model.js +16 -0
- package/lib/esm/models/gemini-chat-model.d.ts +14 -0
- package/lib/esm/models/gemini-chat-model.js +14 -0
- package/lib/esm/models/ollama-chat-model.d.ts +16 -0
- package/lib/esm/models/ollama-chat-model.js +16 -0
- package/lib/esm/models/open-router-chat-model.d.ts +16 -0
- package/lib/esm/models/open-router-chat-model.js +16 -0
- package/lib/esm/models/openai-chat-model.d.ts +67 -3
- package/lib/esm/models/openai-chat-model.js +47 -2
- package/lib/esm/models/xai-chat-model.d.ts +16 -0
- package/lib/esm/models/xai-chat-model.js +16 -0
- package/lib/esm/prompt/prompt-builder.d.ts +4 -4
- package/lib/esm/prompt/prompt-builder.js +20 -19
- package/lib/esm/prompt/prompts/memory-message-template.d.ts +1 -0
- package/lib/esm/prompt/prompts/memory-message-template.js +7 -0
- package/lib/esm/prompt/template.js +5 -1
- package/lib/esm/server/error.d.ts +11 -0
- package/lib/esm/server/error.js +11 -0
- package/lib/esm/server/index.d.ts +2 -0
- package/lib/esm/server/index.js +2 -0
- package/lib/esm/server/server.d.ts +89 -8
- package/lib/esm/server/server.js +58 -0
- package/lib/esm/utils/fs.d.ts +2 -0
- package/lib/esm/utils/fs.js +21 -0
- package/lib/esm/utils/prompts.d.ts +1 -0
- package/lib/esm/utils/prompts.js +10 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +13 -0
- package/package.json +14 -11
- package/lib/cjs/agents/memory.d.ts +0 -26
- package/lib/cjs/agents/memory.js +0 -45
- package/lib/dts/agents/memory.d.ts +0 -26
- package/lib/esm/agents/memory.d.ts +0 -26
- package/lib/esm/agents/memory.js +0 -41
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
import type { Message } from "../agents/agent.js";
|
|
3
3
|
import type { Context } from "./context.js";
|
|
4
|
+
/**
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
4
7
|
export declare const UserInputTopic = "UserInputTopic";
|
|
8
|
+
/**
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
5
11
|
export declare const UserOutputTopic = "UserOutputTopic";
|
|
12
|
+
/**
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
6
15
|
export interface MessagePayload {
|
|
7
16
|
role: "user" | "agent";
|
|
8
17
|
source?: string;
|
|
9
18
|
message: Message;
|
|
10
19
|
context: Context;
|
|
11
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
export declare function toMessagePayload(payload: Omit<MessagePayload, "context"> | string | Message, options?: Partial<Pick<MessagePayload, "role" | "source">>): Omit<MessagePayload, "context">;
|
|
25
|
+
/**
|
|
26
|
+
* @hidden
|
|
27
|
+
*/
|
|
12
28
|
export type MessageQueueListener = (message: MessagePayload) => void;
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
13
32
|
export type Unsubscribe = () => void;
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
14
36
|
export declare class MessageQueue {
|
|
15
37
|
events: EventEmitter<[never]>;
|
|
16
38
|
publish(topic: string | string[], payload: MessagePayload): void;
|
|
17
39
|
error(error: Error): void;
|
|
18
|
-
subscribe(topic: string, listener?: undefined): Promise<MessagePayload>;
|
|
19
|
-
subscribe(topic: string, listener: MessageQueueListener): Unsubscribe;
|
|
20
|
-
subscribe(topic: string, listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
21
|
-
unsubscribe(topic: string, listener: MessageQueueListener): void;
|
|
40
|
+
subscribe(topic: string | string[], listener?: undefined): Promise<MessagePayload>;
|
|
41
|
+
subscribe(topic: string | string[], listener: MessageQueueListener): Unsubscribe;
|
|
42
|
+
subscribe(topic: string | string[], listener?: MessageQueueListener): Unsubscribe | Promise<MessagePayload>;
|
|
43
|
+
unsubscribe(topic: string | string[], listener: MessageQueueListener): void;
|
|
22
44
|
}
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageQueue = exports.UserOutputTopic = exports.UserInputTopic = void 0;
|
|
4
|
+
exports.toMessagePayload = toMessagePayload;
|
|
4
5
|
const node_events_1 = require("node:events");
|
|
5
6
|
const zod_1 = require("zod");
|
|
7
|
+
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
6
8
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
7
12
|
exports.UserInputTopic = "UserInputTopic";
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
8
16
|
exports.UserOutputTopic = "UserOutputTopic";
|
|
17
|
+
function isMessagePayload(payload) {
|
|
18
|
+
return (!(0, type_utils_js_1.isNil)(payload) &&
|
|
19
|
+
typeof payload === "object" &&
|
|
20
|
+
"role" in payload &&
|
|
21
|
+
typeof payload.role === "string" &&
|
|
22
|
+
["user", "agent"].includes(payload.role) &&
|
|
23
|
+
"message" in payload &&
|
|
24
|
+
!(0, type_utils_js_1.isNil)(payload.message));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
function toMessagePayload(payload, options) {
|
|
30
|
+
if (isMessagePayload(payload)) {
|
|
31
|
+
return { ...payload, message: (0, prompt_builder_js_1.createMessage)(payload.message), ...options };
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
role: options?.role || "user",
|
|
35
|
+
source: options?.source,
|
|
36
|
+
message: (0, prompt_builder_js_1.createMessage)(payload),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @hidden
|
|
41
|
+
*/
|
|
9
42
|
class MessageQueue {
|
|
10
43
|
events = new node_events_1.EventEmitter();
|
|
11
44
|
publish(topic, payload) {
|
|
@@ -44,24 +77,26 @@ class MessageQueue {
|
|
|
44
77
|
topic,
|
|
45
78
|
listener,
|
|
46
79
|
});
|
|
47
|
-
|
|
80
|
+
for (const t of (0, type_utils_js_1.orArrayToArray)(topic)) {
|
|
81
|
+
this.events.off(t, listener);
|
|
82
|
+
}
|
|
48
83
|
}
|
|
49
84
|
}
|
|
50
85
|
exports.MessageQueue = MessageQueue;
|
|
51
86
|
function on(events, event, listener) {
|
|
52
|
-
events.on(
|
|
53
|
-
return () => events.off(
|
|
87
|
+
(0, type_utils_js_1.orArrayToArray)(event).forEach((e) => events.on(e, listener));
|
|
88
|
+
return () => (0, type_utils_js_1.orArrayToArray)(event).forEach((e) => events.off(e, listener));
|
|
54
89
|
}
|
|
55
90
|
function once(events, event, listener) {
|
|
56
|
-
events.once(
|
|
57
|
-
return () => events.off(
|
|
91
|
+
(0, type_utils_js_1.orArrayToArray)(event).forEach((e) => events.once(e, listener));
|
|
92
|
+
return () => (0, type_utils_js_1.orArrayToArray)(event).forEach((e) => events.off(e, listener));
|
|
58
93
|
}
|
|
59
94
|
const subscribeArgsSchema = zod_1.z.object({
|
|
60
|
-
topic: zod_1.z.string(),
|
|
95
|
+
topic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]),
|
|
61
96
|
listener: zod_1.z.function(zod_1.z.tuple([zod_1.z.any()]), zod_1.z.any()).optional(),
|
|
62
97
|
});
|
|
63
98
|
const unsubscribeArgsSchema = zod_1.z.object({
|
|
64
|
-
topic: zod_1.z.string(),
|
|
99
|
+
topic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]),
|
|
65
100
|
listener: zod_1.z.function(zod_1.z.tuple([zod_1.z.any()]), zod_1.z.any()),
|
|
66
101
|
});
|
|
67
102
|
const publishArgsSchema = zod_1.z.object({
|
package/lib/cjs/aigne/usage.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
1
4
|
export interface ContextUsage {
|
|
2
5
|
inputTokens: number;
|
|
3
6
|
outputTokens: number;
|
|
4
7
|
agentCalls: number;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
6
12
|
export declare function newEmptyContextUsage(): ContextUsage;
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
7
16
|
export interface ContextLimits {
|
|
8
17
|
maxTokens?: number;
|
|
9
18
|
maxAgentInvokes?: number;
|
package/lib/cjs/aigne/usage.js
CHANGED
|
@@ -1,19 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client module used to interact with the AIGNE framework.
|
|
3
|
+
*/
|
|
1
4
|
import type { AgentInvokeOptions, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the AIGNEClient.
|
|
7
|
+
*/
|
|
2
8
|
export interface AIGNEClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The URL of the AIGNE server to connect to.
|
|
11
|
+
* This should point to the base endpoint where the AIGNEServer is hosted.
|
|
12
|
+
*/
|
|
3
13
|
url: string;
|
|
4
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for invoking an agent through the AIGNEClient.
|
|
17
|
+
* Extends the standard AgentInvokeOptions with client-specific options.
|
|
18
|
+
*/
|
|
5
19
|
export interface AIGNEClientInvokeOptions extends AgentInvokeOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Additional fetch API options to customize the HTTP request.
|
|
22
|
+
* These options will be merged with the default options used by the client.
|
|
23
|
+
*/
|
|
6
24
|
fetchOptions?: Partial<RequestInit>;
|
|
7
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Client for interacting with a remote AIGNE server.
|
|
28
|
+
* AIGNEClient provides a client-side interface that matches the AIGNE API,
|
|
29
|
+
* allowing applications to invoke agents and receive responses from a remote AIGNE instance.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* Here's a simple example of how to use AIGNEClient:
|
|
33
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-simple}
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Here's an example of how to use AIGNEClient with streaming response:
|
|
37
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-streaming}
|
|
38
|
+
*/
|
|
8
39
|
export declare class AIGNEClient {
|
|
9
40
|
options: AIGNEClientOptions;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new AIGNEClient instance.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Configuration options for connecting to the AIGNE server
|
|
45
|
+
*/
|
|
10
46
|
constructor(options: AIGNEClientOptions);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Invokes an agent in non-streaming mode and returns the complete response.
|
|
49
|
+
*
|
|
50
|
+
* @param agent - Name of the agent to invoke
|
|
51
|
+
* @param input - Input message for the agent
|
|
52
|
+
* @param options - Options with streaming mode explicitly set to false or omitted
|
|
53
|
+
* @returns The complete agent response
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Here's a simple example of how to use AIGNEClient:
|
|
57
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-simple}
|
|
58
|
+
*/
|
|
14
59
|
invoke<I extends Message, O extends Message>(agent: string, input: I, options?: AIGNEClientInvokeOptions & {
|
|
15
60
|
streaming?: false;
|
|
16
61
|
}): Promise<O>;
|
|
62
|
+
/**
|
|
63
|
+
* Invokes an agent with streaming mode enabled and returns a stream of response chunks.
|
|
64
|
+
*
|
|
65
|
+
* @param agent - Name of the agent to invoke
|
|
66
|
+
* @param input - Input message for the agent
|
|
67
|
+
* @param options - Options with streaming mode explicitly set to true
|
|
68
|
+
* @returns A stream of agent response chunks
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* Here's an example of how to use AIGNEClient with streaming response:
|
|
72
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-streaming}
|
|
73
|
+
*/
|
|
74
|
+
invoke<I extends Message, O extends Message>(agent: string, input: I, options: AIGNEClientInvokeOptions & {
|
|
75
|
+
streaming: true;
|
|
76
|
+
}): Promise<AgentResponseStream<O>>;
|
|
77
|
+
/**
|
|
78
|
+
* Invokes an agent with the given input and options.
|
|
79
|
+
*
|
|
80
|
+
* @param agent - Name of the agent to invoke
|
|
81
|
+
* @param input - Input message for the agent
|
|
82
|
+
* @param options - Options for the invocation
|
|
83
|
+
* @returns Either a complete response or a response stream depending on the streaming option
|
|
84
|
+
*/
|
|
17
85
|
invoke<I extends Message, O extends Message>(agent: string, input: I, options?: AIGNEClientInvokeOptions): Promise<AgentResponse<O>>;
|
|
86
|
+
/**
|
|
87
|
+
* Enhanced fetch method that handles error responses from the AIGNE server.
|
|
88
|
+
* This method wraps the standard fetch API to provide better error handling and reporting.
|
|
89
|
+
*
|
|
90
|
+
* @param args - Standard fetch API arguments (url and options)
|
|
91
|
+
* @returns A Response object if the request was successful
|
|
92
|
+
* @throws Error with detailed information if the request failed
|
|
93
|
+
*
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
18
96
|
fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response>;
|
|
19
97
|
}
|
package/lib/cjs/client/client.js
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client module used to interact with the AIGNE framework.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AIGNEClient = void 0;
|
|
4
7
|
const event_stream_js_1 = require("../utils/event-stream.js");
|
|
5
8
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
9
|
+
/**
|
|
10
|
+
* Client for interacting with a remote AIGNE server.
|
|
11
|
+
* AIGNEClient provides a client-side interface that matches the AIGNE API,
|
|
12
|
+
* allowing applications to invoke agents and receive responses from a remote AIGNE instance.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* Here's a simple example of how to use AIGNEClient:
|
|
16
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-simple}
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Here's an example of how to use AIGNEClient with streaming response:
|
|
20
|
+
* {@includeCode ../../test/client/client.test.ts#example-aigne-client-streaming}
|
|
21
|
+
*/
|
|
6
22
|
class AIGNEClient {
|
|
7
23
|
options;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new AIGNEClient instance.
|
|
26
|
+
*
|
|
27
|
+
* @param options - Configuration options for connecting to the AIGNE server
|
|
28
|
+
*/
|
|
8
29
|
constructor(options) {
|
|
9
30
|
this.options = options;
|
|
10
31
|
}
|
|
11
32
|
async invoke(agent, input, options) {
|
|
33
|
+
// Send the agent invocation request to the AIGNE server
|
|
12
34
|
const response = await this.fetch(this.options.url, {
|
|
13
35
|
...options?.fetchOptions,
|
|
14
36
|
method: "POST",
|
|
@@ -18,17 +40,33 @@ class AIGNEClient {
|
|
|
18
40
|
},
|
|
19
41
|
body: JSON.stringify({ agent, input, options }),
|
|
20
42
|
});
|
|
43
|
+
// For non-streaming responses, simply parse the JSON response and return it
|
|
21
44
|
if (!options?.streaming) {
|
|
22
45
|
return await response.json();
|
|
23
46
|
}
|
|
47
|
+
// For streaming responses, set up the streaming pipeline
|
|
24
48
|
const stream = response.body;
|
|
25
49
|
if (!stream)
|
|
26
50
|
throw new Error("Response body is not a stream");
|
|
51
|
+
// Process the stream through a series of transforms:
|
|
52
|
+
// 1. Convert bytes to text
|
|
53
|
+
// 2. Parse SSE format into structured events
|
|
54
|
+
// 3. Convert events into a standardized agent response stream
|
|
27
55
|
return stream
|
|
28
56
|
.pipeThrough(new TextDecoderStream())
|
|
29
57
|
.pipeThrough(new event_stream_js_1.EventStreamParser())
|
|
30
58
|
.pipeThrough(new event_stream_js_1.AgentResponseStreamParser());
|
|
31
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Enhanced fetch method that handles error responses from the AIGNE server.
|
|
62
|
+
* This method wraps the standard fetch API to provide better error handling and reporting.
|
|
63
|
+
*
|
|
64
|
+
* @param args - Standard fetch API arguments (url and options)
|
|
65
|
+
* @returns A Response object if the request was successful
|
|
66
|
+
* @throws Error with detailed information if the request failed
|
|
67
|
+
*
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
32
70
|
async fetch(...args) {
|
|
33
71
|
const result = await globalThis.fetch(...args);
|
|
34
72
|
if (!result.ok) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./client.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client.js"), exports);
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from "./agents/agent.js";
|
|
2
2
|
export * from "./agents/ai-agent.js";
|
|
3
3
|
export * from "./agents/mcp-agent.js";
|
|
4
|
-
export * from "./agents/memory.js";
|
|
5
4
|
export * from "./agents/team-agent.js";
|
|
6
5
|
export * from "./agents/types.js";
|
|
7
6
|
export * from "./agents/user-agent.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./agents/agent.js"), exports);
|
|
18
18
|
__exportStar(require("./agents/ai-agent.js"), exports);
|
|
19
19
|
__exportStar(require("./agents/mcp-agent.js"), exports);
|
|
20
|
-
__exportStar(require("./agents/memory.js"), exports);
|
|
21
20
|
__exportStar(require("./agents/team-agent.js"), exports);
|
|
22
21
|
__exportStar(require("./agents/types.js"), exports);
|
|
23
22
|
__exportStar(require("./agents/user-agent.js"), exports);
|
|
@@ -2,7 +2,7 @@ import { type ZodObject, type ZodType, z } from "zod";
|
|
|
2
2
|
import type { Message } from "../agents/agent.js";
|
|
3
3
|
export declare function loadAgentFromJsFile(path: string): Promise<{
|
|
4
4
|
name: string;
|
|
5
|
-
|
|
5
|
+
process: (args_0: Message) => Message;
|
|
6
6
|
description?: string | undefined;
|
|
7
7
|
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
8
8
|
[x: string]: any;
|
|
@@ -51,7 +51,7 @@ const agentJsFileSchema = zod_1.z.object({
|
|
|
51
51
|
output_schema: schema_js_1.inputOutputSchema
|
|
52
52
|
.nullish()
|
|
53
53
|
.transform((v) => (v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined)),
|
|
54
|
-
|
|
54
|
+
process: zod_1.z.function(),
|
|
55
55
|
});
|
|
56
56
|
async function loadAgentFromJsFile(path) {
|
|
57
57
|
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => Promise.resolve(`${path}`).then(s => __importStar(require(s))), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
@@ -61,6 +61,6 @@ async function loadAgentFromJsFile(path) {
|
|
|
61
61
|
return (0, type_utils_js_1.tryOrThrow)(() => (0, camelize_js_1.customCamelize)(agentJsFileSchema.parse({
|
|
62
62
|
...agent,
|
|
63
63
|
name: agent.agent_name || agent.name,
|
|
64
|
-
|
|
64
|
+
process: agent,
|
|
65
65
|
}), { shallowKeys: ["input_schema", "output_schema"] }), (error) => new Error(`Failed to parse agent from ${path}: ${error.message}`));
|
|
66
66
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { type ZodObject, type ZodType, z } from "zod";
|
|
2
|
+
import { AIAgentToolChoice } from "../agents/ai-agent.js";
|
|
2
3
|
export declare function loadAgentFromYamlFile(path: string): Promise<{
|
|
3
4
|
type: "ai";
|
|
4
5
|
name: string;
|
|
5
6
|
description?: string | undefined;
|
|
7
|
+
skills?: string[] | undefined;
|
|
6
8
|
memory?: true | {
|
|
7
9
|
subscribeTopic?: string[] | undefined;
|
|
8
10
|
} | undefined;
|
|
9
|
-
skills?: string[] | undefined;
|
|
10
11
|
instructions?: string | undefined;
|
|
11
12
|
inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
12
13
|
[x: string]: any;
|
|
13
14
|
}, {
|
|
14
15
|
[x: string]: any;
|
|
15
16
|
}> | undefined;
|
|
16
|
-
toolChoice?:
|
|
17
|
+
toolChoice?: AIAgentToolChoice | undefined;
|
|
17
18
|
outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
18
19
|
[x: string]: any;
|
|
19
20
|
}, {
|
|
@@ -5,6 +5,7 @@ const promises_1 = require("node:fs/promises");
|
|
|
5
5
|
const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
|
|
6
6
|
const yaml_1 = require("yaml");
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
|
+
const ai_agent_js_1 = require("../agents/ai-agent.js");
|
|
8
9
|
const camelize_js_1 = require("../utils/camelize.js");
|
|
9
10
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
10
11
|
const schema_js_1 = require("./schema.js");
|
|
@@ -35,7 +36,7 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
|
|
|
35
36
|
.nullish()
|
|
36
37
|
.transform((v) => v ?? undefined),
|
|
37
38
|
tool_choice: zod_1.z
|
|
38
|
-
.
|
|
39
|
+
.nativeEnum(ai_agent_js_1.AIAgentToolChoice)
|
|
39
40
|
.nullish()
|
|
40
41
|
.transform((v) => v ?? undefined),
|
|
41
42
|
memory: zod_1.z
|
|
@@ -8,8 +8,8 @@ export declare function load(options: LoadOptions): Promise<{
|
|
|
8
8
|
model: ChatModel | undefined;
|
|
9
9
|
agents: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
|
|
10
10
|
skills: Agent<import("../agents/agent.js").Message, import("../agents/agent.js").Message>[];
|
|
11
|
-
description?: string | null | undefined;
|
|
12
11
|
name?: string | null | undefined;
|
|
12
|
+
description?: string | null | undefined;
|
|
13
13
|
chat_model?: {
|
|
14
14
|
name?: string | null | undefined;
|
|
15
15
|
temperature?: number | null | undefined;
|
|
@@ -63,8 +63,8 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
63
63
|
agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
64
64
|
skills: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
65
65
|
}, "strip", z.ZodTypeAny, {
|
|
66
|
-
description?: string | null | undefined;
|
|
67
66
|
name?: string | null | undefined;
|
|
67
|
+
description?: string | null | undefined;
|
|
68
68
|
skills?: string[] | null | undefined;
|
|
69
69
|
chat_model?: {
|
|
70
70
|
name?: string | null | undefined;
|
|
@@ -76,8 +76,8 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
76
76
|
} | null | undefined;
|
|
77
77
|
agents?: string[] | null | undefined;
|
|
78
78
|
}, {
|
|
79
|
-
description?: string | null | undefined;
|
|
80
79
|
name?: string | null | undefined;
|
|
80
|
+
description?: string | null | undefined;
|
|
81
81
|
skills?: string[] | null | undefined;
|
|
82
82
|
chat_model?: string | {
|
|
83
83
|
name?: string | null | undefined;
|
|
@@ -90,8 +90,8 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
90
90
|
agents?: string[] | null | undefined;
|
|
91
91
|
}>;
|
|
92
92
|
export declare function loadAIGNEFile(path: string): Promise<{
|
|
93
|
-
description?: string | null | undefined;
|
|
94
93
|
name?: string | null | undefined;
|
|
94
|
+
description?: string | null | undefined;
|
|
95
95
|
skills?: string[] | null | undefined;
|
|
96
96
|
chat_model?: {
|
|
97
97
|
name?: string | null | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Memory, MemoryAgent, type MemoryAgentOptions } from "./memory.js";
|
|
2
|
+
export declare const DEFAULT_MAX_MEMORY_COUNT = 10;
|
|
3
|
+
export interface DefaultMemoryOptions extends Partial<MemoryAgentOptions> {
|
|
4
|
+
}
|
|
5
|
+
export declare class DefaultMemory extends MemoryAgent {
|
|
6
|
+
constructor(options?: DefaultMemoryOptions);
|
|
7
|
+
storage: Memory[];
|
|
8
|
+
search(options?: {
|
|
9
|
+
limit?: number;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
result: Memory[];
|
|
12
|
+
}>;
|
|
13
|
+
create(memory: Pick<Memory, "content">): Promise<{
|
|
14
|
+
result: Memory;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DefaultMemory = exports.DEFAULT_MAX_MEMORY_COUNT = void 0;
|
|
7
|
+
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
8
|
+
const memory_js_1 = require("./memory.js");
|
|
9
|
+
const recorder_js_1 = require("./recorder.js");
|
|
10
|
+
const retriever_js_1 = require("./retriever.js");
|
|
11
|
+
exports.DEFAULT_MAX_MEMORY_COUNT = 10;
|
|
12
|
+
class DefaultMemory extends memory_js_1.MemoryAgent {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super({
|
|
15
|
+
...options,
|
|
16
|
+
autoUpdate: options.autoUpdate ?? true,
|
|
17
|
+
});
|
|
18
|
+
if (!this.recorder)
|
|
19
|
+
this.recorder = new DefaultMemoryRecorder(this);
|
|
20
|
+
if (!this.retriever)
|
|
21
|
+
this.retriever = new DefaultMemoryRetriever(this);
|
|
22
|
+
}
|
|
23
|
+
storage = [];
|
|
24
|
+
async search(options = {}) {
|
|
25
|
+
const { limit = exports.DEFAULT_MAX_MEMORY_COUNT } = options;
|
|
26
|
+
const result = limit < 0 ? this.storage.slice(limit) : this.storage.slice(0, limit);
|
|
27
|
+
return { result };
|
|
28
|
+
}
|
|
29
|
+
async create(memory) {
|
|
30
|
+
const m = {
|
|
31
|
+
...memory,
|
|
32
|
+
id: (0, memory_js_1.newMemoryId)(),
|
|
33
|
+
createdAt: new Date().toISOString(),
|
|
34
|
+
};
|
|
35
|
+
this.storage.push(m);
|
|
36
|
+
return { result: m };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.DefaultMemory = DefaultMemory;
|
|
40
|
+
class DefaultMemoryRetriever extends retriever_js_1.MemoryRetriever {
|
|
41
|
+
memory;
|
|
42
|
+
constructor(memory) {
|
|
43
|
+
super({});
|
|
44
|
+
this.memory = memory;
|
|
45
|
+
}
|
|
46
|
+
async process(input) {
|
|
47
|
+
const { result } = await this.memory.search(input);
|
|
48
|
+
return { memories: result };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class DefaultMemoryRecorder extends recorder_js_1.MemoryRecorder {
|
|
52
|
+
memory;
|
|
53
|
+
constructor(memory) {
|
|
54
|
+
super({});
|
|
55
|
+
this.memory = memory;
|
|
56
|
+
}
|
|
57
|
+
async process(input) {
|
|
58
|
+
const newMemories = [];
|
|
59
|
+
for (const content of input.content) {
|
|
60
|
+
const { result: [last], } = await this.memory.search({ limit: -1 });
|
|
61
|
+
if (!(0, fast_deep_equal_1.default)(last?.content, content)) {
|
|
62
|
+
const { result } = await this.memory.create({ content });
|
|
63
|
+
newMemories.push(result);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
memories: newMemories,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./memory.js"), exports);
|
|
18
|
+
__exportStar(require("./recorder.js"), exports);
|
|
19
|
+
__exportStar(require("./retriever.js"), exports);
|