@aigne/core 1.12.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 +28 -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/loader/index.js +2 -0
- 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 +79 -0
- package/lib/cjs/models/bedrock-chat-model.js +303 -0
- package/lib/cjs/models/chat-model.d.ts +279 -1
- package/lib/cjs/models/chat-model.js +62 -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 +15 -0
- package/lib/cjs/models/gemini-chat-model.js +15 -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 +70 -3
- package/lib/cjs/models/openai-chat-model.js +147 -102
- 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 +21 -20
- 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 +2 -0
- package/lib/cjs/utils/type-utils.js +26 -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 +79 -0
- package/lib/dts/models/chat-model.d.ts +279 -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 +15 -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 +70 -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 +2 -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/loader/index.js +2 -0
- 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 +79 -0
- package/lib/esm/models/bedrock-chat-model.js +298 -0
- package/lib/esm/models/chat-model.d.ts +279 -1
- package/lib/esm/models/chat-model.js +62 -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 +15 -0
- package/lib/esm/models/gemini-chat-model.js +15 -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 +70 -3
- package/lib/esm/models/openai-chat-model.js +147 -102
- 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 +22 -21
- 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 +2 -0
- package/lib/esm/utils/type-utils.js +24 -0
- package/package.json +21 -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,20 +1,19 @@
|
|
|
1
1
|
import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import { Agent, type Message } from "../agents/agent.js";
|
|
3
3
|
import type { AIAgent } from "../agents/ai-agent.js";
|
|
4
|
-
import type { AgentMemory } from "../agents/memory.js";
|
|
5
4
|
import type { Context } from "../aigne/context.js";
|
|
5
|
+
import type { MemoryAgent } from "../memory/memory.js";
|
|
6
6
|
import type { ChatModel, ChatModelInput } from "../models/chat-model.js";
|
|
7
7
|
import { ChatMessagesTemplate } from "./template.js";
|
|
8
8
|
export declare const MESSAGE_KEY = "$message";
|
|
9
|
-
export declare const DEFAULT_MAX_HISTORY_MESSAGES = 10;
|
|
10
9
|
export declare function createMessage<I extends Message>(message: string | I): I;
|
|
11
10
|
export declare function getMessage(input: Message): string | undefined;
|
|
12
11
|
export interface PromptBuilderOptions {
|
|
13
12
|
instructions?: string | ChatMessagesTemplate;
|
|
14
13
|
}
|
|
15
14
|
export interface PromptBuilderBuildOptions {
|
|
16
|
-
memory?:
|
|
17
|
-
context
|
|
15
|
+
memory?: MemoryAgent | MemoryAgent[];
|
|
16
|
+
context: Context;
|
|
18
17
|
agent?: AIAgent;
|
|
19
18
|
input?: Message;
|
|
20
19
|
model?: ChatModel;
|
|
@@ -37,6 +36,7 @@ export declare class PromptBuilder {
|
|
|
37
36
|
toolAgents?: Agent[];
|
|
38
37
|
}>;
|
|
39
38
|
private buildMessages;
|
|
39
|
+
private convertMemoriesToMessages;
|
|
40
40
|
private buildResponseFormat;
|
|
41
41
|
private buildTools;
|
|
42
42
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MEMORY_MESSAGE_TEMPLATE = "Here are some useful memories to consider:\n\n<memories>\n{{memories}}\n</memories>\n";
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class for AIGNEServer HTTP-related errors.
|
|
3
|
+
* Extends the standard Error class with an HTTP status code property.
|
|
4
|
+
* This allows error responses to include appropriate HTTP status codes.
|
|
5
|
+
*/
|
|
1
6
|
export declare class ServerError extends Error {
|
|
2
7
|
status: number;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new ServerError instance.
|
|
10
|
+
*
|
|
11
|
+
* @param status - The HTTP status code for this error (e.g., 400, 404, 500)
|
|
12
|
+
* @param message - The error message describing what went wrong
|
|
13
|
+
*/
|
|
3
14
|
constructor(status: number, message: string);
|
|
4
15
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import type { AIGNE } from "../aigne/aigne.js";
|
|
4
|
+
/**
|
|
5
|
+
* Schema for validating agent invocation payloads.
|
|
6
|
+
* Defines the expected structure for requests to invoke an agent.
|
|
7
|
+
*
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
4
10
|
export declare const invokePayloadSchema: z.ZodObject<{
|
|
5
11
|
agent: z.ZodString;
|
|
6
12
|
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
@@ -24,31 +30,106 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
24
30
|
streaming?: boolean | null | undefined;
|
|
25
31
|
} | null | undefined;
|
|
26
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for the AIGNEServer.
|
|
35
|
+
* These options control various aspects of server behavior including
|
|
36
|
+
* request parsing, payload limits, and response handling.
|
|
37
|
+
*/
|
|
27
38
|
export interface AIGNEServerOptions {
|
|
28
39
|
/**
|
|
29
|
-
* Maximum body size for
|
|
30
|
-
*
|
|
40
|
+
* Maximum body size for incoming HTTP requests.
|
|
41
|
+
* This controls the upper limit of request payload size when parsing raw HTTP requests.
|
|
42
|
+
* Only used when working with Node.js IncomingMessage objects that don't already have
|
|
43
|
+
* a pre-parsed body property (e.g., when not using Express middleware).
|
|
44
|
+
*
|
|
31
45
|
* @default "4mb"
|
|
32
46
|
*/
|
|
33
47
|
maximumBodySize?: string;
|
|
34
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* AIGNEServer provides HTTP API access to AIGNE capabilities.
|
|
51
|
+
* It handles requests to invoke agents, manages response streaming,
|
|
52
|
+
* and supports multiple HTTP server frameworks including Node.js http,
|
|
53
|
+
* Express, and Fetch API compatible environments.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Here's a simple example of how to use AIGNEServer with express:
|
|
57
|
+
* {@includeCode ../../test/server/server.test.ts#example-aigne-server-express}
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* Here's an example of how to use AIGNEServer with Hono:
|
|
61
|
+
* {@includeCode ../../test/server/server.test.ts#example-aigne-server-hono}
|
|
62
|
+
*/
|
|
35
63
|
export declare class AIGNEServer {
|
|
36
64
|
engine: AIGNE;
|
|
37
65
|
options?: AIGNEServerOptions | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new AIGNEServer instance.
|
|
68
|
+
*
|
|
69
|
+
* @param engine - The AIGNE engine instance that will process agent invocations
|
|
70
|
+
* @param options - Configuration options for the server
|
|
71
|
+
*/
|
|
38
72
|
constructor(engine: AIGNE, options?: AIGNEServerOptions | undefined);
|
|
39
73
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
74
|
+
* Invokes an agent with the provided input and returns a standard web Response.
|
|
75
|
+
* This method serves as the primary API endpoint for agent invocation.
|
|
76
|
+
*
|
|
77
|
+
* The request can be provided in various formats to support different integration scenarios:
|
|
78
|
+
* - As a pre-parsed JavaScript object
|
|
79
|
+
* - As a Fetch API Request instance (for modern web frameworks)
|
|
80
|
+
* - As a Node.js IncomingMessage (for Express, Fastify, etc.)
|
|
81
|
+
*
|
|
82
|
+
* @param request - The agent invocation request in any supported format
|
|
83
|
+
* @returns A web standard Response object that can be returned directly in frameworks
|
|
84
|
+
* like Hono, Next.js, or any Fetch API compatible environment
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* Here's a simple example of how to use AIGNEServer with Hono:
|
|
88
|
+
* {@includeCode ../../test/server/server.test.ts#example-aigne-server-hono}
|
|
43
89
|
*/
|
|
44
90
|
invoke(request: Record<string, unknown> | Request | IncomingMessage): Promise<Response>;
|
|
45
91
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
92
|
+
* Invokes an agent with the provided input and streams the response to a Node.js ServerResponse.
|
|
93
|
+
* This overload is specifically designed for Node.js HTTP server environments.
|
|
94
|
+
*
|
|
95
|
+
* The method handles both regular JSON responses and streaming Server-Sent Events (SSE)
|
|
96
|
+
* responses based on the options specified in the request.
|
|
97
|
+
*
|
|
98
|
+
* @param request - The agent invocation request in any supported format
|
|
99
|
+
* @param response - The Node.js ServerResponse object to write the response to
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* Here's a simple example of how to use AIGNEServer with express:
|
|
103
|
+
* {@includeCode ../../test/server/server.test.ts#example-aigne-server-express}
|
|
49
104
|
*/
|
|
50
105
|
invoke(request: Record<string, unknown> | Request | IncomingMessage, response: ServerResponse): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Internal method that handles the core logic of processing an agent invocation request.
|
|
108
|
+
* Validates the request payload, finds the requested agent, and processes the invocation
|
|
109
|
+
* with either streaming or non-streaming response handling.
|
|
110
|
+
*
|
|
111
|
+
* @param request - The parsed or raw request to process
|
|
112
|
+
* @returns A standard Response object with the invocation result
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
51
115
|
_invoke(request: Record<string, unknown> | Request | IncomingMessage): Promise<Response>;
|
|
116
|
+
/**
|
|
117
|
+
* Prepares and normalizes the input from various request types.
|
|
118
|
+
* Handles different request formats (Node.js IncomingMessage, Fetch API Request,
|
|
119
|
+
* or already parsed object) and extracts the JSON payload.
|
|
120
|
+
*
|
|
121
|
+
* @param request - The request object in any supported format
|
|
122
|
+
* @returns The normalized payload as a JavaScript object
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
52
125
|
_prepareInput(request: Record<string, unknown> | Request | IncomingMessage): Promise<Record<string, unknown>>;
|
|
126
|
+
/**
|
|
127
|
+
* Writes a web standard Response object to a Node.js ServerResponse.
|
|
128
|
+
* Handles streaming responses and error conditions appropriately.
|
|
129
|
+
*
|
|
130
|
+
* @param response - The web standard Response object to write
|
|
131
|
+
* @param res - The Node.js ServerResponse to write to
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
53
134
|
_writeResponse(response: Response, res: ServerResponse): Promise<void>;
|
|
54
135
|
}
|
|
@@ -8,6 +8,8 @@ export declare function isEmpty(obj: unknown): boolean;
|
|
|
8
8
|
export declare function isNonNullable<T>(value: T): value is NonNullable<T>;
|
|
9
9
|
export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
|
|
10
10
|
export declare function duplicates<T>(arr: T[], key?: (item: T) => unknown): T[];
|
|
11
|
+
export declare function remove<T>(arr: T[], remove: T[] | ((item: T) => boolean)): T[];
|
|
12
|
+
export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
|
|
11
13
|
export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
|
|
12
14
|
export declare function orArrayToArray<T>(value?: T | T[]): T[];
|
|
13
15
|
export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
|