@aigne/core 1.14.0 → 1.16.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 (145) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +9 -7
  3. package/README.zh.md +9 -7
  4. package/lib/cjs/agents/agent.d.ts +129 -6
  5. package/lib/cjs/agents/agent.js +112 -20
  6. package/lib/cjs/agents/ai-agent.d.ts +3 -2
  7. package/lib/cjs/agents/ai-agent.js +12 -9
  8. package/lib/{esm/models → cjs/agents}/chat-model.d.ts +24 -13
  9. package/lib/cjs/{models → agents}/chat-model.js +48 -7
  10. package/lib/cjs/agents/guide-rail-agent.d.ts +62 -0
  11. package/lib/cjs/agents/guide-rail-agent.js +14 -0
  12. package/lib/cjs/agents/mcp-agent.js +9 -9
  13. package/lib/cjs/agents/team-agent.js +1 -1
  14. package/lib/cjs/aigne/aigne.d.ts +3 -2
  15. package/lib/cjs/aigne/aigne.js +2 -2
  16. package/lib/cjs/aigne/context.d.ts +2 -1
  17. package/lib/cjs/aigne/context.js +8 -1
  18. package/lib/cjs/index.d.ts +1 -1
  19. package/lib/cjs/index.js +1 -1
  20. package/lib/cjs/loader/agent-yaml.d.ts +1 -1
  21. package/lib/cjs/loader/index.d.ts +18 -11
  22. package/lib/cjs/loader/index.js +8 -27
  23. package/lib/cjs/memory/retriever.d.ts +2 -2
  24. package/lib/cjs/prompt/prompt-builder.d.ts +3 -3
  25. package/lib/cjs/prompt/template.d.ts +3 -3
  26. package/lib/cjs/prompt/template.js +1 -1
  27. package/lib/cjs/utils/json-schema.js +1 -1
  28. package/lib/cjs/utils/logger.d.ts +33 -8
  29. package/lib/cjs/utils/logger.js +63 -5
  30. package/lib/cjs/utils/model-utils.d.ts +1 -1
  31. package/lib/cjs/utils/stream-utils.d.ts +3 -2
  32. package/lib/cjs/utils/stream-utils.js +50 -26
  33. package/lib/cjs/utils/type-utils.d.ts +5 -0
  34. package/lib/dts/agents/agent.d.ts +129 -6
  35. package/lib/dts/agents/ai-agent.d.ts +3 -2
  36. package/lib/{cjs/models → dts/agents}/chat-model.d.ts +24 -13
  37. package/lib/dts/agents/guide-rail-agent.d.ts +62 -0
  38. package/lib/dts/aigne/aigne.d.ts +3 -2
  39. package/lib/dts/aigne/context.d.ts +2 -1
  40. package/lib/dts/index.d.ts +1 -1
  41. package/lib/dts/loader/agent-yaml.d.ts +1 -1
  42. package/lib/dts/loader/index.d.ts +18 -11
  43. package/lib/dts/memory/retriever.d.ts +2 -2
  44. package/lib/dts/prompt/prompt-builder.d.ts +3 -3
  45. package/lib/dts/prompt/template.d.ts +3 -3
  46. package/lib/dts/utils/logger.d.ts +33 -8
  47. package/lib/dts/utils/model-utils.d.ts +1 -1
  48. package/lib/dts/utils/stream-utils.d.ts +3 -2
  49. package/lib/dts/utils/type-utils.d.ts +5 -0
  50. package/lib/esm/agents/agent.d.ts +129 -6
  51. package/lib/esm/agents/agent.js +112 -20
  52. package/lib/esm/agents/ai-agent.d.ts +3 -2
  53. package/lib/esm/agents/ai-agent.js +12 -9
  54. package/lib/{dts/models → esm/agents}/chat-model.d.ts +24 -13
  55. package/lib/esm/{models → agents}/chat-model.js +48 -7
  56. package/lib/esm/agents/guide-rail-agent.d.ts +62 -0
  57. package/lib/esm/agents/guide-rail-agent.js +11 -0
  58. package/lib/esm/agents/mcp-agent.js +9 -9
  59. package/lib/esm/agents/team-agent.js +2 -2
  60. package/lib/esm/aigne/aigne.d.ts +3 -2
  61. package/lib/esm/aigne/aigne.js +2 -2
  62. package/lib/esm/aigne/context.d.ts +2 -1
  63. package/lib/esm/aigne/context.js +9 -2
  64. package/lib/esm/index.d.ts +1 -1
  65. package/lib/esm/index.js +1 -1
  66. package/lib/esm/loader/agent-yaml.d.ts +1 -1
  67. package/lib/esm/loader/index.d.ts +18 -11
  68. package/lib/esm/loader/index.js +8 -27
  69. package/lib/esm/memory/retriever.d.ts +2 -2
  70. package/lib/esm/prompt/prompt-builder.d.ts +3 -3
  71. package/lib/esm/prompt/template.d.ts +3 -3
  72. package/lib/esm/prompt/template.js +1 -1
  73. package/lib/esm/utils/json-schema.js +1 -1
  74. package/lib/esm/utils/logger.d.ts +33 -8
  75. package/lib/esm/utils/logger.js +61 -4
  76. package/lib/esm/utils/model-utils.d.ts +1 -1
  77. package/lib/esm/utils/stream-utils.d.ts +3 -2
  78. package/lib/esm/utils/stream-utils.js +48 -25
  79. package/lib/esm/utils/type-utils.d.ts +5 -0
  80. package/package.json +1 -20
  81. package/lib/cjs/client/client.d.ts +0 -97
  82. package/lib/cjs/client/client.js +0 -87
  83. package/lib/cjs/client/index.d.ts +0 -1
  84. package/lib/cjs/client/index.js +0 -17
  85. package/lib/cjs/models/bedrock-chat-model.d.ts +0 -79
  86. package/lib/cjs/models/bedrock-chat-model.js +0 -303
  87. package/lib/cjs/models/claude-chat-model.d.ts +0 -114
  88. package/lib/cjs/models/claude-chat-model.js +0 -317
  89. package/lib/cjs/models/deepseek-chat-model.d.ts +0 -23
  90. package/lib/cjs/models/deepseek-chat-model.js +0 -35
  91. package/lib/cjs/models/gemini-chat-model.d.ts +0 -23
  92. package/lib/cjs/models/gemini-chat-model.js +0 -35
  93. package/lib/cjs/models/ollama-chat-model.d.ts +0 -22
  94. package/lib/cjs/models/ollama-chat-model.js +0 -34
  95. package/lib/cjs/models/open-router-chat-model.d.ts +0 -22
  96. package/lib/cjs/models/open-router-chat-model.js +0 -34
  97. package/lib/cjs/models/openai-chat-model.d.ts +0 -166
  98. package/lib/cjs/models/openai-chat-model.js +0 -415
  99. package/lib/cjs/models/xai-chat-model.d.ts +0 -21
  100. package/lib/cjs/models/xai-chat-model.js +0 -33
  101. package/lib/cjs/server/error.d.ts +0 -15
  102. package/lib/cjs/server/error.js +0 -22
  103. package/lib/cjs/server/index.d.ts +0 -2
  104. package/lib/cjs/server/index.js +0 -18
  105. package/lib/cjs/server/server.d.ts +0 -135
  106. package/lib/cjs/server/server.js +0 -188
  107. package/lib/dts/client/client.d.ts +0 -97
  108. package/lib/dts/client/index.d.ts +0 -1
  109. package/lib/dts/models/bedrock-chat-model.d.ts +0 -79
  110. package/lib/dts/models/claude-chat-model.d.ts +0 -114
  111. package/lib/dts/models/deepseek-chat-model.d.ts +0 -23
  112. package/lib/dts/models/gemini-chat-model.d.ts +0 -23
  113. package/lib/dts/models/ollama-chat-model.d.ts +0 -22
  114. package/lib/dts/models/open-router-chat-model.d.ts +0 -22
  115. package/lib/dts/models/openai-chat-model.d.ts +0 -166
  116. package/lib/dts/models/xai-chat-model.d.ts +0 -21
  117. package/lib/dts/server/error.d.ts +0 -15
  118. package/lib/dts/server/index.d.ts +0 -2
  119. package/lib/dts/server/server.d.ts +0 -135
  120. package/lib/esm/client/client.d.ts +0 -97
  121. package/lib/esm/client/client.js +0 -83
  122. package/lib/esm/client/index.d.ts +0 -1
  123. package/lib/esm/client/index.js +0 -1
  124. package/lib/esm/models/bedrock-chat-model.d.ts +0 -79
  125. package/lib/esm/models/bedrock-chat-model.js +0 -298
  126. package/lib/esm/models/claude-chat-model.d.ts +0 -114
  127. package/lib/esm/models/claude-chat-model.js +0 -310
  128. package/lib/esm/models/deepseek-chat-model.d.ts +0 -23
  129. package/lib/esm/models/deepseek-chat-model.js +0 -31
  130. package/lib/esm/models/gemini-chat-model.d.ts +0 -23
  131. package/lib/esm/models/gemini-chat-model.js +0 -31
  132. package/lib/esm/models/ollama-chat-model.d.ts +0 -22
  133. package/lib/esm/models/ollama-chat-model.js +0 -30
  134. package/lib/esm/models/open-router-chat-model.d.ts +0 -22
  135. package/lib/esm/models/open-router-chat-model.js +0 -30
  136. package/lib/esm/models/openai-chat-model.d.ts +0 -166
  137. package/lib/esm/models/openai-chat-model.js +0 -405
  138. package/lib/esm/models/xai-chat-model.d.ts +0 -21
  139. package/lib/esm/models/xai-chat-model.js +0 -29
  140. package/lib/esm/server/error.d.ts +0 -15
  141. package/lib/esm/server/error.js +0 -18
  142. package/lib/esm/server/index.d.ts +0 -2
  143. package/lib/esm/server/index.js +0 -2
  144. package/lib/esm/server/server.d.ts +0 -135
  145. package/lib/esm/server/server.js +0 -181
@@ -1,6 +1,6 @@
1
- import { Agent, type AgentProcessResult, type Message } from "../agents/agent.js";
2
1
  import type { Context } from "../aigne/context.js";
3
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import { Agent, type AgentProcessResult, type Message } from "./agent.js";
4
4
  /**
5
5
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
6
6
  *
@@ -10,19 +10,19 @@ import type { PromiseOrValue } from "../utils/type-utils.js";
10
10
  *
11
11
  * @example
12
12
  * Here's how to implement a custom ChatModel:
13
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model}
13
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model}
14
14
  *
15
15
  * @example
16
16
  * Here's an example showing streaming response with readable stream:
17
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-streaming}
17
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-streaming}
18
18
  *
19
19
  * @example
20
20
  * Here's an example showing streaming response with async generator:
21
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-streaming-async-generator}
21
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-streaming-async-generator}
22
22
  *
23
23
  * @example
24
24
  * Here's an example with tool calls:
25
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
25
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
26
26
  */
27
27
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
28
28
  constructor();
@@ -44,6 +44,17 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
44
44
  supportsParallelToolCalls: boolean;
45
45
  };
46
46
  private validateToolNames;
47
+ /**
48
+ * Normalizes tool names to ensure compatibility with language models
49
+ *
50
+ * This method converts tool names to a format that complies with model requirements
51
+ * by replacing hyphens and whitespace characters with underscores. The normalized
52
+ * names are used for tool calls while preserving the original names for reference.
53
+ *
54
+ * @param name - The original tool name to normalize
55
+ * @returns A promise that resolves to the normalized tool name
56
+ */
57
+ protected normalizeToolName(name: string): Promise<string>;
47
58
  /**
48
59
  * Performs preprocessing operations before handling input
49
60
  *
@@ -53,7 +64,7 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
53
64
  * @param context Execution context
54
65
  * @throws Error if token usage exceeds maximum limit
55
66
  */
56
- protected preprocess(input: ChatModelInput, context: Context): void;
67
+ protected preprocess(input: ChatModelInput, context: Context): Promise<void>;
57
68
  /**
58
69
  * Performs postprocessing operations after handling output
59
70
  *
@@ -94,11 +105,11 @@ export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelO
94
105
  *
95
106
  * @example
96
107
  * Here's a basic ChatModel input example:
97
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model}
108
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model}
98
109
  *
99
110
  * @example
100
111
  * Here's an example with tool calling:
101
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
112
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
102
113
  */
103
114
  export interface ChatModelInput extends Message {
104
115
  /**
@@ -213,7 +224,7 @@ export type ChatModelInputResponseFormat = {
213
224
  *
214
225
  * @example
215
226
  * Here's an example showing how to use tools:
216
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
227
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
217
228
  */
218
229
  export interface ChatModelInputTool {
219
230
  /**
@@ -249,7 +260,7 @@ export interface ChatModelInputTool {
249
260
  *
250
261
  * @example
251
262
  * Here's an example showing how to use tools:
252
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
263
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
253
264
  */
254
265
  export type ChatModelInputToolChoice = "auto" | "none" | "required" | {
255
266
  type: "function";
@@ -296,11 +307,11 @@ export interface ChatModelOptions {
296
307
  *
297
308
  * @example
298
309
  * Here's a basic output example:
299
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model}
310
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model}
300
311
  *
301
312
  * @example
302
313
  * Here's an example with tool calls:
303
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
314
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
304
315
  */
305
316
  export interface ChatModelOutput extends Message {
306
317
  /**
@@ -331,7 +342,7 @@ export interface ChatModelOutput extends Message {
331
342
  *
332
343
  * @example
333
344
  * Here's an example with tool calls:
334
- * {@includeCode ../../test/models/chat-model.test.ts#example-chat-model-tools}
345
+ * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
335
346
  */
336
347
  export interface ChatModelOutputToolCall {
337
348
  /**
@@ -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>;
@@ -1,6 +1,7 @@
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 { ChatModel } from "../models/chat-model.js";
4
+ import { type LoadOptions } from "../loader/index.js";
4
5
  import { AIGNEContext, type InvokeOptions } 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";
@@ -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?: AIGNEOptions): Promise<AIGNE>;
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
  *
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from "node:events";
2
2
  import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
+ import type { ChatModel } from "../agents/chat-model.js";
3
4
  import { UserAgent } from "../agents/user-agent.js";
4
- import type { ChatModel } from "../models/chat-model.js";
5
5
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
6
6
  import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emtter.js";
7
7
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
@@ -41,6 +41,7 @@ export type ContextEmitEventMap = {
41
41
  export interface InvokeOptions extends AgentInvokeOptions {
42
42
  returnActiveAgent?: boolean;
43
43
  disableTransfer?: boolean;
44
+ sourceAgent?: Agent;
44
45
  }
45
46
  /**
46
47
  * @hidden
@@ -5,6 +5,6 @@ export * from "./agents/team-agent.js";
5
5
  export * from "./agents/types.js";
6
6
  export * from "./agents/user-agent.js";
7
7
  export * from "./aigne/index.js";
8
- export * from "./models/chat-model.js";
8
+ export * from "./agents/chat-model.js";
9
9
  export * from "./prompt/prompt-builder.js";
10
10
  export * from "./prompt/template.js";
@@ -14,13 +14,13 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
14
14
  }, {
15
15
  [x: string]: any;
16
16
  }> | undefined;
17
- toolChoice?: AIAgentToolChoice | undefined;
18
17
  outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
19
18
  [x: string]: any;
20
19
  }, {
21
20
  [x: string]: any;
22
21
  }> | undefined;
23
22
  outputKey?: string | undefined;
23
+ toolChoice?: AIAgentToolChoice | undefined;
24
24
  } | {
25
25
  type: "mcp";
26
26
  url?: string | undefined;
@@ -1,7 +1,14 @@
1
+ import type { Camelize } from "camelize-ts";
1
2
  import { z } from "zod";
2
3
  import { type Agent } from "../agents/agent.js";
3
- import type { ChatModel, ChatModelOptions } from "../models/chat-model.js";
4
+ import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
4
5
  export interface LoadOptions {
6
+ models: {
7
+ new (parameters: {
8
+ model?: string;
9
+ modelOptions?: ChatModelOptions;
10
+ }): ChatModel;
11
+ }[];
5
12
  path: string;
6
13
  }
7
14
  export declare function load(options: LoadOptions): Promise<{
@@ -15,12 +22,12 @@ export declare function load(options: LoadOptions): Promise<{
15
22
  temperature?: number | null | undefined;
16
23
  provider?: string | null | undefined;
17
24
  top_p?: number | null | undefined;
18
- frequent_penalty?: number | null | undefined;
25
+ frequency_penalty?: number | null | undefined;
19
26
  presence_penalty?: number | null | undefined;
20
27
  } | null | undefined;
21
28
  }>;
22
29
  export declare function loadAgent(path: string): Promise<Agent>;
23
- export declare function loadModel(model?: z.infer<typeof aigneFileSchema>["chat_model"], modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
30
+ export declare function loadModel(models: LoadOptions["models"], model?: Camelize<z.infer<typeof aigneFileSchema>["chat_model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
24
31
  declare const aigneFileSchema: z.ZodObject<{
25
32
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
33
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -29,35 +36,35 @@ declare const aigneFileSchema: z.ZodObject<{
29
36
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
37
  temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
31
38
  top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
32
- frequent_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
39
+ frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
33
40
  presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
41
  }, "strip", z.ZodTypeAny, {
35
42
  name?: string | null | undefined;
36
43
  temperature?: number | null | undefined;
37
44
  provider?: string | null | undefined;
38
45
  top_p?: number | null | undefined;
39
- frequent_penalty?: number | null | undefined;
46
+ frequency_penalty?: number | null | undefined;
40
47
  presence_penalty?: number | null | undefined;
41
48
  }, {
42
49
  name?: string | null | undefined;
43
50
  temperature?: number | null | undefined;
44
51
  provider?: string | null | undefined;
45
52
  top_p?: number | null | undefined;
46
- frequent_penalty?: number | null | undefined;
53
+ frequency_penalty?: number | null | undefined;
47
54
  presence_penalty?: number | null | undefined;
48
55
  }>]>>>, {
49
56
  name?: string | null | undefined;
50
57
  temperature?: number | null | undefined;
51
58
  provider?: string | null | undefined;
52
59
  top_p?: number | null | undefined;
53
- frequent_penalty?: number | null | undefined;
60
+ frequency_penalty?: number | null | undefined;
54
61
  presence_penalty?: number | null | undefined;
55
62
  } | null | undefined, string | {
56
63
  name?: string | null | undefined;
57
64
  temperature?: number | null | undefined;
58
65
  provider?: string | null | undefined;
59
66
  top_p?: number | null | undefined;
60
- frequent_penalty?: number | null | undefined;
67
+ frequency_penalty?: number | null | undefined;
61
68
  presence_penalty?: number | null | undefined;
62
69
  } | null | undefined>;
63
70
  agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
@@ -71,7 +78,7 @@ declare const aigneFileSchema: z.ZodObject<{
71
78
  temperature?: number | null | undefined;
72
79
  provider?: string | null | undefined;
73
80
  top_p?: number | null | undefined;
74
- frequent_penalty?: number | null | undefined;
81
+ frequency_penalty?: number | null | undefined;
75
82
  presence_penalty?: number | null | undefined;
76
83
  } | null | undefined;
77
84
  agents?: string[] | null | undefined;
@@ -84,7 +91,7 @@ declare const aigneFileSchema: z.ZodObject<{
84
91
  temperature?: number | null | undefined;
85
92
  provider?: string | null | undefined;
86
93
  top_p?: number | null | undefined;
87
- frequent_penalty?: number | null | undefined;
94
+ frequency_penalty?: number | null | undefined;
88
95
  presence_penalty?: number | null | undefined;
89
96
  } | null | undefined;
90
97
  agents?: string[] | null | undefined;
@@ -98,7 +105,7 @@ export declare function loadAIGNEFile(path: string): Promise<{
98
105
  temperature?: number | null | undefined;
99
106
  provider?: string | null | undefined;
100
107
  top_p?: number | null | undefined;
101
- frequent_penalty?: number | null | undefined;
108
+ frequency_penalty?: number | null | undefined;
102
109
  presence_penalty?: number | null | undefined;
103
110
  } | null | undefined;
104
111
  agents?: string[] | null | undefined;
@@ -39,11 +39,11 @@ export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
39
  limit: z.ZodOptional<z.ZodNumber>;
40
40
  search: z.ZodOptional<z.ZodString>;
41
41
  }, "strip", z.ZodTypeAny, {
42
- limit?: number | undefined;
43
42
  search?: string | undefined;
44
- }, {
45
43
  limit?: number | undefined;
44
+ }, {
46
45
  search?: string | undefined;
46
+ limit?: number | undefined;
47
47
  }>;
48
48
  /**
49
49
  * @hidden
@@ -1,9 +1,9 @@
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 { ChatModel, ChatModelInput } from "../agents/chat-model.js";
4
5
  import type { Context } from "../aigne/context.js";
5
6
  import type { MemoryAgent } from "../memory/memory.js";
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
9
  export declare function createMessage<I extends Message>(message: string | I): I;
@@ -11,7 +11,7 @@ export declare function getMessage(input: Message): string | undefined;
11
11
  export interface PromptBuilderOptions {
12
12
  instructions?: string | ChatMessagesTemplate;
13
13
  }
14
- export interface PromptBuilderBuildOptions {
14
+ export interface PromptBuildOptions {
15
15
  memory?: MemoryAgent | MemoryAgent[];
16
16
  context: Context;
17
17
  agent?: AIAgent;
@@ -32,7 +32,7 @@ export declare class PromptBuilder {
32
32
  private static fromMCPPromptResult;
33
33
  constructor(options?: PromptBuilderOptions);
34
34
  instructions?: string | ChatMessagesTemplate;
35
- build(options: PromptBuilderBuildOptions): Promise<ChatModelInput & {
35
+ build(options: PromptBuildOptions): Promise<ChatModelInput & {
36
36
  toolAgents?: Agent[];
37
37
  }>;
38
38
  private buildMessages;
@@ -1,4 +1,4 @@
1
- import type { ChatModelInputMessage, ChatModelInputMessageContent, ChatModelOutputToolCall } from "../models/chat-model.js";
1
+ import type { ChatModelInputMessage, ChatModelInputMessageContent, ChatModelOutputToolCall } from "../agents/chat-model.js";
2
2
  export declare class PromptTemplate {
3
3
  template: string;
4
4
  static from(template: string): PromptTemplate;
@@ -24,7 +24,7 @@ export declare class AgentMessageTemplate extends ChatMessageTemplate {
24
24
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string);
25
25
  format(variables?: Record<string, unknown>): {
26
26
  toolCalls: ChatModelOutputToolCall[] | undefined;
27
- role: import("../models/chat-model.js").Role;
27
+ role: import("../agents/chat-model.js").Role;
28
28
  content?: ChatModelInputMessageContent;
29
29
  toolCallId?: string;
30
30
  name?: string;
@@ -36,7 +36,7 @@ export declare class ToolMessageTemplate extends ChatMessageTemplate {
36
36
  constructor(content: object | string, toolCallId: string, name?: string);
37
37
  format(variables?: Record<string, unknown>): {
38
38
  toolCallId: string;
39
- role: import("../models/chat-model.js").Role;
39
+ role: import("../agents/chat-model.js").Role;
40
40
  content?: ChatModelInputMessageContent;
41
41
  toolCalls?: {
42
42
  id: string;
@@ -1,8 +1,33 @@
1
- import debug from "debug";
2
- export declare const logger: debug.Debug & {
3
- debug: debug.Debug;
4
- default: debug.Debug;
5
- } & {
6
- core: debug.Debugger;
7
- mcp: debug.Debugger;
8
- };
1
+ export declare enum LogLevel {
2
+ ERROR = "error",
3
+ WARN = "warn",
4
+ INFO = "info",
5
+ DEBUG = "debug"
6
+ }
7
+ export declare class Logger {
8
+ constructor(options: {
9
+ level: LogLevel;
10
+ ns: string;
11
+ });
12
+ level: LogLevel;
13
+ private debugLogger;
14
+ private infoLogger;
15
+ private warnLogger;
16
+ private errorLogger;
17
+ logMessage: {
18
+ (...data: any[]): void;
19
+ (...data: any[]): void;
20
+ (message?: any, ...optionalParams: any[]): void;
21
+ };
22
+ logError: {
23
+ (...data: any[]): void;
24
+ (...data: any[]): void;
25
+ (message?: any, ...optionalParams: any[]): void;
26
+ };
27
+ debug(message: string, ...args: unknown[]): void;
28
+ info(message: string, ...args: unknown[]): void;
29
+ warn(message: string, ...args: unknown[]): void;
30
+ error(message: string, ...args: unknown[]): void;
31
+ enabled(level: LogLevel): boolean;
32
+ }
33
+ export declare const logger: Logger;
@@ -1,3 +1,3 @@
1
- import type { ChatModelOutputUsage } from "../models/chat-model.js";
1
+ import type { ChatModelOutputUsage } from "../agents/chat-model.js";
2
2
  import type { Nullish } from "./type-utils.js";
3
3
  export declare function mergeUsage(...usages: Nullish<ChatModelOutputUsage>[]): ChatModelOutputUsage;
@@ -6,7 +6,7 @@ export declare function mergeAgentResponseChunk<T extends Message>(output: T, ch
6
6
  export declare function agentResponseStreamToObject<T extends Message>(stream: AgentResponseStream<T> | AgentProcessAsyncGenerator<T>): Promise<T>;
7
7
  export declare function asyncGeneratorToReadableStream<T extends Message>(generator: AgentProcessAsyncGenerator<T>): AgentResponseStream<T>;
8
8
  export declare function onAgentResponseStreamEnd<T extends Message>(stream: AgentResponseStream<T>, callback: (result: T) => PromiseOrValue<Partial<T> | void>, options?: {
9
- errorCallback?: (error: Error) => Error;
9
+ errorCallback?: (error: Error) => PromiseOrValue<Error>;
10
10
  processChunk?: (chunk: AgentResponseChunk<T>) => AgentResponseChunk<T>;
11
11
  }): ReadableStream<any>;
12
12
  export declare function isAsyncGenerator<T extends AsyncGenerator>(value: AsyncGenerator | unknown): value is T;
@@ -18,5 +18,6 @@ export declare function readableStreamToArray<T>(stream: ReadableStream<T>, opti
18
18
  export declare function readableStreamToArray<T>(stream: ReadableStream<T>, options?: {
19
19
  catchError?: false;
20
20
  }): Promise<T[]>;
21
- export declare function readableStreamToAsyncIterator<T>(stream: ReadableStream<T>): AsyncIterable<T>;
22
21
  export declare function stringToAgentResponseStream(str: string, key?: "text" | typeof MESSAGE_KEY | string): AgentResponseStream<Message>;
22
+ export declare function toReadableStream(stream: NodeJS.ReadStream): ReadableStream<Uint8Array<ArrayBufferLike>>;
23
+ export declare function readAllString(stream: NodeJS.ReadStream | ReadableStream): Promise<string>;
@@ -2,6 +2,11 @@ import { type ZodType } from "zod";
2
2
  export type PromiseOrValue<T> = T | Promise<T>;
3
3
  export type Nullish<T> = T | null | undefined | void;
4
4
  export type OmitPropertiesFromArrayFirstElement<T extends unknown[], K extends string | number | symbol> = T extends [infer U, ...infer Rest] ? [Omit<U, K>, ...Rest] : never;
5
+ export type XOr<T, K extends keyof T, O extends keyof T> = (Omit<T, O> & {
6
+ [key in O]?: undefined;
7
+ }) | (Omit<T, K> & {
8
+ [key in K]?: undefined;
9
+ });
5
10
  export declare function isNil(value: unknown): value is null | undefined;
6
11
  export declare function isRecord<T>(value: unknown): value is Record<string, T>;
7
12
  export declare function isEmpty(obj: unknown): boolean;