@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.
Files changed (195) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +13 -26
  3. package/README.zh.md +24 -37
  4. package/lib/cjs/agents/agent.d.ts +522 -15
  5. package/lib/cjs/agents/agent.js +357 -36
  6. package/lib/cjs/agents/ai-agent.d.ts +210 -52
  7. package/lib/cjs/agents/ai-agent.js +182 -24
  8. package/lib/cjs/agents/mcp-agent.d.ts +112 -0
  9. package/lib/cjs/agents/mcp-agent.js +79 -1
  10. package/lib/cjs/agents/team-agent.d.ts +99 -0
  11. package/lib/cjs/agents/team-agent.js +94 -0
  12. package/lib/cjs/agents/user-agent.d.ts +6 -4
  13. package/lib/cjs/agents/user-agent.js +16 -5
  14. package/lib/cjs/aigne/aigne.d.ts +263 -16
  15. package/lib/cjs/aigne/aigne.js +130 -20
  16. package/lib/cjs/aigne/context.d.ts +24 -8
  17. package/lib/cjs/aigne/context.js +8 -22
  18. package/lib/cjs/aigne/message-queue.d.ts +26 -4
  19. package/lib/cjs/aigne/message-queue.js +42 -7
  20. package/lib/cjs/aigne/usage.d.ts +9 -0
  21. package/lib/cjs/aigne/usage.js +3 -0
  22. package/lib/cjs/client/client.d.ts +81 -3
  23. package/lib/cjs/client/client.js +38 -0
  24. package/lib/cjs/client/index.d.ts +1 -0
  25. package/lib/cjs/client/index.js +17 -0
  26. package/lib/cjs/index.d.ts +0 -1
  27. package/lib/cjs/index.js +0 -1
  28. package/lib/cjs/loader/agent-js.d.ts +1 -1
  29. package/lib/cjs/loader/agent-js.js +2 -2
  30. package/lib/cjs/loader/agent-yaml.d.ts +3 -2
  31. package/lib/cjs/loader/agent-yaml.js +2 -1
  32. package/lib/cjs/loader/index.d.ts +4 -4
  33. package/lib/cjs/memory/default-memory.d.ts +16 -0
  34. package/lib/cjs/memory/default-memory.js +70 -0
  35. package/lib/cjs/memory/index.d.ts +3 -0
  36. package/lib/cjs/memory/index.js +19 -0
  37. package/lib/cjs/memory/memory.d.ts +89 -0
  38. package/lib/cjs/memory/memory.js +132 -0
  39. package/lib/cjs/memory/recorder.d.ts +86 -0
  40. package/lib/cjs/memory/recorder.js +50 -0
  41. package/lib/cjs/memory/retriever.d.ts +99 -0
  42. package/lib/cjs/memory/retriever.js +51 -0
  43. package/lib/cjs/models/bedrock-chat-model.d.ts +12 -3
  44. package/lib/cjs/models/bedrock-chat-model.js +54 -24
  45. package/lib/cjs/models/chat-model.d.ts +278 -1
  46. package/lib/cjs/models/chat-model.js +54 -0
  47. package/lib/cjs/models/claude-chat-model.d.ts +49 -3
  48. package/lib/cjs/models/claude-chat-model.js +34 -2
  49. package/lib/cjs/models/deepseek-chat-model.d.ts +16 -0
  50. package/lib/cjs/models/deepseek-chat-model.js +16 -0
  51. package/lib/cjs/models/gemini-chat-model.d.ts +14 -0
  52. package/lib/cjs/models/gemini-chat-model.js +14 -0
  53. package/lib/cjs/models/ollama-chat-model.d.ts +16 -0
  54. package/lib/cjs/models/ollama-chat-model.js +16 -0
  55. package/lib/cjs/models/open-router-chat-model.d.ts +16 -0
  56. package/lib/cjs/models/open-router-chat-model.js +16 -0
  57. package/lib/cjs/models/openai-chat-model.d.ts +67 -3
  58. package/lib/cjs/models/openai-chat-model.js +47 -2
  59. package/lib/cjs/models/xai-chat-model.d.ts +16 -0
  60. package/lib/cjs/models/xai-chat-model.js +16 -0
  61. package/lib/cjs/prompt/prompt-builder.d.ts +4 -4
  62. package/lib/cjs/prompt/prompt-builder.js +19 -18
  63. package/lib/cjs/prompt/prompts/memory-message-template.d.ts +1 -0
  64. package/lib/cjs/prompt/prompts/memory-message-template.js +10 -0
  65. package/lib/cjs/prompt/template.js +5 -1
  66. package/lib/cjs/server/error.d.ts +11 -0
  67. package/lib/cjs/server/error.js +11 -0
  68. package/lib/cjs/server/index.d.ts +2 -0
  69. package/lib/cjs/server/index.js +18 -0
  70. package/lib/cjs/server/server.d.ts +89 -8
  71. package/lib/cjs/server/server.js +58 -0
  72. package/lib/cjs/utils/fs.d.ts +2 -0
  73. package/lib/cjs/utils/fs.js +25 -0
  74. package/lib/cjs/utils/prompts.d.ts +1 -0
  75. package/lib/cjs/utils/prompts.js +11 -2
  76. package/lib/cjs/utils/type-utils.d.ts +1 -0
  77. package/lib/cjs/utils/type-utils.js +14 -0
  78. package/lib/dts/agents/agent.d.ts +522 -15
  79. package/lib/dts/agents/ai-agent.d.ts +210 -52
  80. package/lib/dts/agents/mcp-agent.d.ts +112 -0
  81. package/lib/dts/agents/team-agent.d.ts +99 -0
  82. package/lib/dts/agents/user-agent.d.ts +6 -4
  83. package/lib/dts/aigne/aigne.d.ts +263 -16
  84. package/lib/dts/aigne/context.d.ts +24 -8
  85. package/lib/dts/aigne/message-queue.d.ts +26 -4
  86. package/lib/dts/aigne/usage.d.ts +9 -0
  87. package/lib/dts/client/client.d.ts +81 -3
  88. package/lib/dts/client/index.d.ts +1 -0
  89. package/lib/dts/index.d.ts +0 -1
  90. package/lib/dts/loader/agent-js.d.ts +1 -1
  91. package/lib/dts/loader/agent-yaml.d.ts +3 -2
  92. package/lib/dts/loader/index.d.ts +4 -4
  93. package/lib/dts/memory/default-memory.d.ts +16 -0
  94. package/lib/dts/memory/index.d.ts +3 -0
  95. package/lib/dts/memory/memory.d.ts +89 -0
  96. package/lib/dts/memory/recorder.d.ts +86 -0
  97. package/lib/dts/memory/retriever.d.ts +99 -0
  98. package/lib/dts/models/bedrock-chat-model.d.ts +12 -3
  99. package/lib/dts/models/chat-model.d.ts +278 -1
  100. package/lib/dts/models/claude-chat-model.d.ts +49 -3
  101. package/lib/dts/models/deepseek-chat-model.d.ts +16 -0
  102. package/lib/dts/models/gemini-chat-model.d.ts +14 -0
  103. package/lib/dts/models/ollama-chat-model.d.ts +16 -0
  104. package/lib/dts/models/open-router-chat-model.d.ts +16 -0
  105. package/lib/dts/models/openai-chat-model.d.ts +67 -3
  106. package/lib/dts/models/xai-chat-model.d.ts +16 -0
  107. package/lib/dts/prompt/prompt-builder.d.ts +4 -4
  108. package/lib/dts/prompt/prompts/memory-message-template.d.ts +1 -0
  109. package/lib/dts/server/error.d.ts +11 -0
  110. package/lib/dts/server/index.d.ts +2 -0
  111. package/lib/dts/server/server.d.ts +89 -8
  112. package/lib/dts/utils/fs.d.ts +2 -0
  113. package/lib/dts/utils/prompts.d.ts +1 -0
  114. package/lib/dts/utils/type-utils.d.ts +1 -0
  115. package/lib/esm/agents/agent.d.ts +522 -15
  116. package/lib/esm/agents/agent.js +351 -35
  117. package/lib/esm/agents/ai-agent.d.ts +210 -52
  118. package/lib/esm/agents/ai-agent.js +183 -25
  119. package/lib/esm/agents/mcp-agent.d.ts +112 -0
  120. package/lib/esm/agents/mcp-agent.js +79 -1
  121. package/lib/esm/agents/team-agent.d.ts +99 -0
  122. package/lib/esm/agents/team-agent.js +94 -0
  123. package/lib/esm/agents/user-agent.d.ts +6 -4
  124. package/lib/esm/agents/user-agent.js +17 -6
  125. package/lib/esm/aigne/aigne.d.ts +263 -16
  126. package/lib/esm/aigne/aigne.js +132 -22
  127. package/lib/esm/aigne/context.d.ts +24 -8
  128. package/lib/esm/aigne/context.js +9 -22
  129. package/lib/esm/aigne/message-queue.d.ts +26 -4
  130. package/lib/esm/aigne/message-queue.js +42 -8
  131. package/lib/esm/aigne/usage.d.ts +9 -0
  132. package/lib/esm/aigne/usage.js +3 -0
  133. package/lib/esm/client/client.d.ts +81 -3
  134. package/lib/esm/client/client.js +38 -0
  135. package/lib/esm/client/index.d.ts +1 -0
  136. package/lib/esm/client/index.js +1 -0
  137. package/lib/esm/index.d.ts +0 -1
  138. package/lib/esm/index.js +0 -1
  139. package/lib/esm/loader/agent-js.d.ts +1 -1
  140. package/lib/esm/loader/agent-js.js +2 -2
  141. package/lib/esm/loader/agent-yaml.d.ts +3 -2
  142. package/lib/esm/loader/agent-yaml.js +2 -1
  143. package/lib/esm/loader/index.d.ts +4 -4
  144. package/lib/esm/memory/default-memory.d.ts +16 -0
  145. package/lib/esm/memory/default-memory.js +63 -0
  146. package/lib/esm/memory/index.d.ts +3 -0
  147. package/lib/esm/memory/index.js +3 -0
  148. package/lib/esm/memory/memory.d.ts +89 -0
  149. package/lib/esm/memory/memory.js +127 -0
  150. package/lib/esm/memory/recorder.d.ts +86 -0
  151. package/lib/esm/memory/recorder.js +46 -0
  152. package/lib/esm/memory/retriever.d.ts +99 -0
  153. package/lib/esm/memory/retriever.js +47 -0
  154. package/lib/esm/models/bedrock-chat-model.d.ts +12 -3
  155. package/lib/esm/models/bedrock-chat-model.js +56 -26
  156. package/lib/esm/models/chat-model.d.ts +278 -1
  157. package/lib/esm/models/chat-model.js +54 -0
  158. package/lib/esm/models/claude-chat-model.d.ts +49 -3
  159. package/lib/esm/models/claude-chat-model.js +35 -3
  160. package/lib/esm/models/deepseek-chat-model.d.ts +16 -0
  161. package/lib/esm/models/deepseek-chat-model.js +16 -0
  162. package/lib/esm/models/gemini-chat-model.d.ts +14 -0
  163. package/lib/esm/models/gemini-chat-model.js +14 -0
  164. package/lib/esm/models/ollama-chat-model.d.ts +16 -0
  165. package/lib/esm/models/ollama-chat-model.js +16 -0
  166. package/lib/esm/models/open-router-chat-model.d.ts +16 -0
  167. package/lib/esm/models/open-router-chat-model.js +16 -0
  168. package/lib/esm/models/openai-chat-model.d.ts +67 -3
  169. package/lib/esm/models/openai-chat-model.js +47 -2
  170. package/lib/esm/models/xai-chat-model.d.ts +16 -0
  171. package/lib/esm/models/xai-chat-model.js +16 -0
  172. package/lib/esm/prompt/prompt-builder.d.ts +4 -4
  173. package/lib/esm/prompt/prompt-builder.js +20 -19
  174. package/lib/esm/prompt/prompts/memory-message-template.d.ts +1 -0
  175. package/lib/esm/prompt/prompts/memory-message-template.js +7 -0
  176. package/lib/esm/prompt/template.js +5 -1
  177. package/lib/esm/server/error.d.ts +11 -0
  178. package/lib/esm/server/error.js +11 -0
  179. package/lib/esm/server/index.d.ts +2 -0
  180. package/lib/esm/server/index.js +2 -0
  181. package/lib/esm/server/server.d.ts +89 -8
  182. package/lib/esm/server/server.js +58 -0
  183. package/lib/esm/utils/fs.d.ts +2 -0
  184. package/lib/esm/utils/fs.js +21 -0
  185. package/lib/esm/utils/prompts.d.ts +1 -0
  186. package/lib/esm/utils/prompts.js +10 -2
  187. package/lib/esm/utils/type-utils.d.ts +1 -0
  188. package/lib/esm/utils/type-utils.js +13 -0
  189. package/package.json +14 -11
  190. package/lib/cjs/agents/memory.d.ts +0 -26
  191. package/lib/cjs/agents/memory.js +0 -45
  192. package/lib/dts/agents/memory.d.ts +0 -26
  193. package/lib/esm/agents/memory.d.ts +0 -26
  194. package/lib/esm/agents/memory.js +0 -41
  195. /package/{LICENSE → LICENSE.md} +0 -0
@@ -1,13 +1,32 @@
1
1
  import Anthropic from "@anthropic-ai/sdk";
2
2
  import { z } from "zod";
3
- import type { AgentInvokeOptions, AgentResponse } from "../agents/agent.js";
4
- import type { Context } from "../aigne/context.js";
3
+ import type { AgentProcessResult } from "../agents/agent.js";
4
+ import { type PromiseOrValue } from "../utils/type-utils.js";
5
5
  import { ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "./chat-model.js";
6
+ /**
7
+ * Configuration options for Claude Chat Model
8
+ */
6
9
  export interface ClaudeChatModelOptions {
10
+ /**
11
+ * API key for Anthropic's Claude API
12
+ *
13
+ * If not provided, will look for ANTHROPIC_API_KEY or CLAUDE_API_KEY in environment variables
14
+ */
7
15
  apiKey?: string;
16
+ /**
17
+ * Claude model to use
18
+ *
19
+ * Defaults to 'claude-3-7-sonnet-latest'
20
+ */
8
21
  model?: string;
22
+ /**
23
+ * Additional model options to control behavior
24
+ */
9
25
  modelOptions?: ChatModelOptions;
10
26
  }
27
+ /**
28
+ * @hidden
29
+ */
11
30
  export declare const claudeChatModelOptionsSchema: z.ZodObject<{
12
31
  apiKey: z.ZodOptional<z.ZodString>;
13
32
  model: z.ZodOptional<z.ZodString>;
@@ -56,13 +75,40 @@ export declare const claudeChatModelOptionsSchema: z.ZodObject<{
56
75
  model?: string | undefined;
57
76
  apiKey?: string | undefined;
58
77
  }>;
78
+ /**
79
+ * Implementation of the ChatModel interface for Anthropic's Claude API
80
+ *
81
+ * This model provides access to Claude's capabilities including:
82
+ * - Text generation
83
+ * - Tool use
84
+ * - JSON structured output
85
+ *
86
+ * Default model: 'claude-3-7-sonnet-latest'
87
+ *
88
+ * @example
89
+ * Here's how to create and use a Claude chat model:
90
+ * {@includeCode ../../test/models/claude-chat-model.test.ts#example-claude-chat-model}
91
+ *
92
+ * @example
93
+ * Here's an example with streaming response:
94
+ * {@includeCode ../../test/models/claude-chat-model.test.ts#example-claude-chat-model-streaming-async-generator}
95
+ */
59
96
  export declare class ClaudeChatModel extends ChatModel {
60
97
  options?: ClaudeChatModelOptions | undefined;
61
98
  constructor(options?: ClaudeChatModelOptions | undefined);
99
+ /**
100
+ * @hidden
101
+ */
62
102
  protected _client?: Anthropic;
63
103
  get client(): Anthropic;
64
104
  get modelOptions(): ChatModelOptions | undefined;
65
- process(input: ChatModelInput, _context: Context, options?: AgentInvokeOptions): Promise<AgentResponse<ChatModelOutput>>;
105
+ /**
106
+ * Process the input using Claude's chat model
107
+ * @param input - The input to process
108
+ * @returns The processed output from the model
109
+ */
110
+ process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
111
+ private _process;
66
112
  private extractResultFromClaudeStream;
67
113
  private requestStructuredOutput;
68
114
  }
@@ -1,4 +1,20 @@
1
1
  import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ /**
3
+ * Implementation of the ChatModel interface for DeepSeek's API
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with DeepSeek's models,
6
+ * but with specific configuration and capabilities for DeepSeek.
7
+ *
8
+ * Default model: 'deepseek-chat'
9
+ *
10
+ * @example
11
+ * Here's how to create and use a DeepSeek chat model:
12
+ * {@includeCode ../../test/models/deepseek-chat-model.test.ts#example-deepseek-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../../test/models/deepseek-chat-model.test.ts#example-deepseek-chat-model-streaming}
17
+ */
2
18
  export declare class DeepSeekChatModel extends OpenAIChatModel {
3
19
  constructor(options?: OpenAIChatModelOptions);
4
20
  protected apiKeyEnvName: string;
@@ -1,4 +1,18 @@
1
1
  import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ /**
3
+ * Implementation of the ChatModel interface for Google's Gemini API
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with Google's Gemini models,
6
+ * providing access to models like Gemini 1.5 and Gemini 2.0.
7
+ *
8
+ * @example
9
+ * Here's how to create and use a Gemini chat model:
10
+ * {@includeCode ../../test/models/gemini-chat-model.test.ts#example-gemini-chat-model}
11
+ *
12
+ * @example
13
+ * Here's an example with streaming response:
14
+ * {@includeCode ../../test/models/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
15
+ */
2
16
  export declare class GeminiChatModel extends OpenAIChatModel {
3
17
  constructor(options?: OpenAIChatModelOptions);
4
18
  protected apiKeyEnvName: string;
@@ -1,4 +1,20 @@
1
1
  import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ /**
3
+ * Implementation of the ChatModel interface for Ollama
4
+ *
5
+ * This model allows you to run open-source LLMs locally using Ollama,
6
+ * with an OpenAI-compatible API interface.
7
+ *
8
+ * Default model: 'llama3.2'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an Ollama chat model:
12
+ * {@includeCode ../../test/models/ollama-chat-model.test.ts#example-ollama-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../../test/models/ollama-chat-model.test.ts#example-ollama-chat-model-streaming}
17
+ */
2
18
  export declare class OllamaChatModel extends OpenAIChatModel {
3
19
  constructor(options?: OpenAIChatModelOptions);
4
20
  protected apiKeyEnvName: string;
@@ -1,4 +1,20 @@
1
1
  import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ /**
3
+ * Implementation of the ChatModel interface for OpenRouter service
4
+ *
5
+ * OpenRouter provides access to a variety of large language models through a unified API.
6
+ * This implementation uses the OpenAI-compatible interface to connect to OpenRouter's service.
7
+ *
8
+ * Default model: 'openai/gpt-4o'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an OpenRouter chat model:
12
+ * {@includeCode ../../test/models/open-router-chat-model.test.ts#example-openrouter-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../../test/models/open-router-chat-model.test.ts#example-openrouter-chat-model-streaming}
17
+ */
2
18
  export declare class OpenRouterChatModel extends OpenAIChatModel {
3
19
  constructor(options?: OpenAIChatModelOptions);
4
20
  protected apiKeyEnvName: string;
@@ -1,8 +1,8 @@
1
1
  import OpenAI from "openai";
2
2
  import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
3
3
  import { z } from "zod";
4
- import type { AgentInvokeOptions, AgentResponse } from "../agents/agent.js";
5
- import type { Context } from "../aigne/context.js";
4
+ import type { AgentProcessResult } from "../agents/agent.js";
5
+ import { type PromiseOrValue } from "../utils/type-utils.js";
6
6
  import { ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "./chat-model.js";
7
7
  export interface OpenAIChatModelCapabilities {
8
8
  supportsNativeStructuredOutputs: boolean;
@@ -13,12 +13,36 @@ export interface OpenAIChatModelCapabilities {
13
13
  supportsToolStreaming: boolean;
14
14
  supportsTemperature: boolean;
15
15
  }
16
+ /**
17
+ * Configuration options for OpenAI Chat Model
18
+ */
16
19
  export interface OpenAIChatModelOptions {
20
+ /**
21
+ * API key for OpenAI API
22
+ *
23
+ * If not provided, will look for OPENAI_API_KEY in environment variables
24
+ */
17
25
  apiKey?: string;
26
+ /**
27
+ * Base URL for OpenAI API
28
+ *
29
+ * Useful for proxies or alternate endpoints
30
+ */
18
31
  baseURL?: string;
32
+ /**
33
+ * OpenAI model to use
34
+ *
35
+ * Defaults to 'gpt-4o-mini'
36
+ */
19
37
  model?: string;
38
+ /**
39
+ * Additional model options to control behavior
40
+ */
20
41
  modelOptions?: ChatModelOptions;
21
42
  }
43
+ /**
44
+ * @hidden
45
+ */
22
46
  export declare const openAIChatModelOptionsSchema: z.ZodObject<{
23
47
  apiKey: z.ZodOptional<z.ZodString>;
24
48
  baseURL: z.ZodOptional<z.ZodString>;
@@ -70,9 +94,31 @@ export declare const openAIChatModelOptionsSchema: z.ZodObject<{
70
94
  apiKey?: string | undefined;
71
95
  baseURL?: string | undefined;
72
96
  }>;
97
+ /**
98
+ * Implementation of the ChatModel interface for OpenAI's API
99
+ *
100
+ * This model provides access to OpenAI's capabilities including:
101
+ * - Text generation
102
+ * - Tool use with parallel tool calls
103
+ * - JSON structured output
104
+ * - Image understanding
105
+ *
106
+ * Default model: 'gpt-4o-mini'
107
+ *
108
+ * @example
109
+ * Here's how to create and use an OpenAI chat model:
110
+ * {@includeCode ../../test/models/openai-chat-model.test.ts#example-openai-chat-model}
111
+ *
112
+ * @example
113
+ * Here's an example with streaming response:
114
+ * {@includeCode ../../test/models/openai-chat-model.test.ts#example-openai-chat-model-streaming}
115
+ */
73
116
  export declare class OpenAIChatModel extends ChatModel {
74
117
  options?: OpenAIChatModelOptions | undefined;
75
118
  constructor(options?: OpenAIChatModelOptions | undefined);
119
+ /**
120
+ * @hidden
121
+ */
76
122
  protected _client?: OpenAI;
77
123
  protected apiKeyEnvName: string;
78
124
  protected apiKeyDefault: string | undefined;
@@ -85,18 +131,36 @@ export declare class OpenAIChatModel extends ChatModel {
85
131
  protected supportsTemperature: boolean;
86
132
  get client(): OpenAI;
87
133
  get modelOptions(): ChatModelOptions | undefined;
88
- process(input: ChatModelInput, _context: Context, options?: AgentInvokeOptions): Promise<AgentResponse<ChatModelOutput>>;
134
+ /**
135
+ * Process the input and generate a response
136
+ * @param input The input to process
137
+ * @returns The generated response
138
+ */
139
+ process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
140
+ private _process;
89
141
  private getParallelToolCalls;
90
142
  private getRunMessages;
91
143
  private getRunResponseFormat;
92
144
  private requestStructuredOutput;
93
145
  private extractResultFromStream;
94
146
  }
147
+ /**
148
+ * @hidden
149
+ */
95
150
  export declare const ROLE_MAP: {
96
151
  [key in Role]: ChatCompletionMessageParam["role"];
97
152
  };
153
+ /**
154
+ * @hidden
155
+ */
98
156
  export declare function contentsFromInputMessages(messages: ChatModelInputMessage[]): Promise<ChatCompletionMessageParam[]>;
157
+ /**
158
+ * @hidden
159
+ */
99
160
  export declare function toolsFromInputTools(tools?: ChatModelInputTool[], options?: {
100
161
  addTypeToEmptyParameters?: boolean;
101
162
  }): ChatCompletionTool[] | undefined;
163
+ /**
164
+ * @hidden
165
+ */
102
166
  export declare function jsonSchemaToOpenAIJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;
@@ -1,4 +1,20 @@
1
1
  import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ /**
3
+ * Implementation of the ChatModel interface for X.AI's API (Grok)
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
6
+ * providing access to models like Grok.
7
+ *
8
+ * Default model: 'grok-2-latest'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an X.AI chat model:
12
+ * {@includeCode ../../test/models/xai-chat-model.test.ts#example-xai-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../../test/models/xai-chat-model.test.ts#example-xai-chat-model-streaming}
17
+ */
2
18
  export declare class XAIChatModel extends OpenAIChatModel {
3
19
  constructor(options?: OpenAIChatModelOptions);
4
20
  protected apiKeyEnvName: string;
@@ -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?: AgentMemory;
17
- context?: 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
  }
@@ -0,0 +1,2 @@
1
+ export * from "./error.js";
2
+ export * from "./server.js";
@@ -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 the request.
30
- * Only used when the request is a Node.js IncomingMessage and no `body` property is present.
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
- * Invoke the agent with the given input.
41
- * @param request - The request object, which can be a parsed JSON object, a Fetch API Request object, or a Node.js IncomingMessage object.
42
- * @returns The web standard response, you can return it directly in supported frameworks like hono.
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
- * Invoke the agent with the given input, and write the SSE response to the Node.js ServerResponse.
47
- * @param request - The request object, which can be a parsed JSON object, a Fetch API Request object, or a Node.js IncomingMessage object.
48
- * @param response - The Node.js ServerResponse object to write the SSE response to.
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
  }
@@ -0,0 +1,2 @@
1
+ export declare function exists(path: string): Promise<boolean>;
2
+ export declare function expandHome(filepath: string): string;
@@ -1 +1,2 @@
1
1
  export declare function getJsonOutputPrompt(schema: Record<string, unknown> | string): string;
2
+ export declare function getJsonToolInputPrompt(schema: Record<string, unknown> | string): string;
@@ -8,6 +8,7 @@ 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[];
11
12
  export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
12
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>;
13
14
  export declare function orArrayToArray<T>(value?: T | T[]): T[];