@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,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,8 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServerError = void 0;
4
+ /**
5
+ * Custom error class for AIGNEServer HTTP-related errors.
6
+ * Extends the standard Error class with an HTTP status code property.
7
+ * This allows error responses to include appropriate HTTP status codes.
8
+ */
4
9
  class ServerError extends Error {
5
10
  status;
11
+ /**
12
+ * Creates a new ServerError instance.
13
+ *
14
+ * @param status - The HTTP status code for this error (e.g., 400, 404, 500)
15
+ * @param message - The error message describing what went wrong
16
+ */
6
17
  constructor(status, message) {
7
18
  super(message);
8
19
  this.status = status;
@@ -0,0 +1,2 @@
1
+ export * from "./error.js";
2
+ export * from "./server.js";
@@ -0,0 +1,18 @@
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("./error.js"), exports);
18
+ __exportStar(require("./server.js"), exports);
@@ -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
  }
@@ -12,7 +12,19 @@ const event_stream_js_1 = require("../utils/event-stream.js");
12
12
  const stream_utils_js_1 = require("../utils/stream-utils.js");
13
13
  const type_utils_js_1 = require("../utils/type-utils.js");
14
14
  const error_js_1 = require("./error.js");
15
+ /**
16
+ * Default maximum allowed size for request bodies when parsing raw HTTP requests.
17
+ * This limits the amount of data that can be uploaded to protect against denial of service attacks.
18
+ * Can be overridden via AIGNEServerOptions.
19
+ * @internal
20
+ */
15
21
  const DEFAULT_MAXIMUM_BODY_SIZE = "4mb";
22
+ /**
23
+ * Schema for validating agent invocation payloads.
24
+ * Defines the expected structure for requests to invoke an agent.
25
+ *
26
+ * @hidden
27
+ */
16
28
  exports.invokePayloadSchema = zod_1.z.object({
17
29
  agent: zod_1.z.string(),
18
30
  input: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
@@ -22,9 +34,29 @@ exports.invokePayloadSchema = zod_1.z.object({
22
34
  })
23
35
  .nullish(),
24
36
  });
37
+ /**
38
+ * AIGNEServer provides HTTP API access to AIGNE capabilities.
39
+ * It handles requests to invoke agents, manages response streaming,
40
+ * and supports multiple HTTP server frameworks including Node.js http,
41
+ * Express, and Fetch API compatible environments.
42
+ *
43
+ * @example
44
+ * Here's a simple example of how to use AIGNEServer with express:
45
+ * {@includeCode ../../test/server/server.test.ts#example-aigne-server-express}
46
+ *
47
+ * @example
48
+ * Here's an example of how to use AIGNEServer with Hono:
49
+ * {@includeCode ../../test/server/server.test.ts#example-aigne-server-hono}
50
+ */
25
51
  class AIGNEServer {
26
52
  engine;
27
53
  options;
54
+ /**
55
+ * Creates a new AIGNEServer instance.
56
+ *
57
+ * @param engine - The AIGNE engine instance that will process agent invocations
58
+ * @param options - Configuration options for the server
59
+ */
28
60
  constructor(engine, options) {
29
61
  this.engine = engine;
30
62
  this.options = options;
@@ -37,6 +69,15 @@ class AIGNEServer {
37
69
  }
38
70
  return result;
39
71
  }
72
+ /**
73
+ * Internal method that handles the core logic of processing an agent invocation request.
74
+ * Validates the request payload, finds the requested agent, and processes the invocation
75
+ * with either streaming or non-streaming response handling.
76
+ *
77
+ * @param request - The parsed or raw request to process
78
+ * @returns A standard Response object with the invocation result
79
+ * @private
80
+ */
40
81
  async _invoke(request) {
41
82
  const { engine } = this;
42
83
  try {
@@ -67,6 +108,15 @@ class AIGNEServer {
67
108
  });
68
109
  }
69
110
  }
111
+ /**
112
+ * Prepares and normalizes the input from various request types.
113
+ * Handles different request formats (Node.js IncomingMessage, Fetch API Request,
114
+ * or already parsed object) and extracts the JSON payload.
115
+ *
116
+ * @param request - The request object in any supported format
117
+ * @returns The normalized payload as a JavaScript object
118
+ * @private
119
+ */
70
120
  async _prepareInput(request) {
71
121
  const contentTypeError = new error_js_1.ServerError(415, "Unsupported Media Type: Content-Type must be application/json");
72
122
  if (request instanceof node_http_1.IncomingMessage) {
@@ -98,6 +148,14 @@ class AIGNEServer {
98
148
  throw contentTypeError;
99
149
  return request;
100
150
  }
151
+ /**
152
+ * Writes a web standard Response object to a Node.js ServerResponse.
153
+ * Handles streaming responses and error conditions appropriately.
154
+ *
155
+ * @param response - The web standard Response object to write
156
+ * @param res - The Node.js ServerResponse to write to
157
+ * @private
158
+ */
101
159
  async _writeResponse(response, res) {
102
160
  try {
103
161
  res.writeHead(response.status, response.headers.toJSON());
@@ -0,0 +1,2 @@
1
+ export declare function exists(path: string): Promise<boolean>;
2
+ export declare function expandHome(filepath: string): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exists = exists;
4
+ exports.expandHome = expandHome;
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_os_1 = require("node:os");
7
+ const node_path_1 = require("node:path");
8
+ async function exists(path) {
9
+ try {
10
+ await (0, promises_1.stat)(path);
11
+ return true;
12
+ }
13
+ catch (e) {
14
+ if (e.code === "ENOENT") {
15
+ return false;
16
+ }
17
+ throw e;
18
+ }
19
+ }
20
+ function expandHome(filepath) {
21
+ if (filepath.startsWith("~/") || filepath === "~") {
22
+ return (0, node_path_1.join)((0, node_os_1.homedir)(), filepath.slice(1));
23
+ }
24
+ return filepath;
25
+ }
@@ -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;
@@ -1,13 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJsonOutputPrompt = getJsonOutputPrompt;
4
- function getJsonOutputPrompt(schema) {
5
- let prompt = "Output must be a JSON object containing the following fields only.";
4
+ exports.getJsonToolInputPrompt = getJsonToolInputPrompt;
5
+ function buildJsonPrompt(schema, firstLine) {
6
+ let prompt = firstLine;
6
7
  if (typeof schema === "string") {
7
8
  prompt += `\n<json_fields>\n${schema}\n</json_fields>`;
8
9
  }
9
10
  else {
10
11
  prompt += `\n<json_fields>\n${JSON.stringify(schema)}\n</json_fields>`;
11
12
  }
13
+ prompt +=
14
+ "\nDo not include any explanations, comments, or Markdown formatting (such as triple backticks). Return only the raw JSON.";
12
15
  return prompt;
13
16
  }
17
+ function getJsonOutputPrompt(schema) {
18
+ return buildJsonPrompt(schema, "Output must be a JSON object containing the following fields only.");
19
+ }
20
+ function getJsonToolInputPrompt(schema) {
21
+ return buildJsonPrompt(schema, "Tool input must be a JSON object containing the following fields only.");
22
+ }
@@ -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[];
@@ -6,6 +6,7 @@ exports.isEmpty = isEmpty;
6
6
  exports.isNonNullable = isNonNullable;
7
7
  exports.isNotEmpty = isNotEmpty;
8
8
  exports.duplicates = duplicates;
9
+ exports.remove = remove;
9
10
  exports.unique = unique;
10
11
  exports.omitBy = omitBy;
11
12
  exports.orArrayToArray = orArrayToArray;
@@ -48,6 +49,19 @@ function duplicates(arr, key = (item) => item) {
48
49
  }
49
50
  return Array.from(duplicates);
50
51
  }
52
+ function remove(arr, remove) {
53
+ const removed = [];
54
+ for (let i = 0; i < arr.length; i++) {
55
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
56
+ const item = arr[i];
57
+ if ((Array.isArray(remove) && remove.includes(item)) ||
58
+ (typeof remove === "function" && remove(item))) {
59
+ removed.push(...arr.splice(i, 1));
60
+ i--;
61
+ }
62
+ }
63
+ return removed;
64
+ }
51
65
  function unique(arr, key = (item) => item) {
52
66
  const seen = new Set();
53
67
  return arr.filter((item) => {