@aigne/core 1.7.0 → 1.9.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 (67) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/lib/cjs/agents/agent.js +2 -2
  3. package/lib/cjs/agents/mcp-agent.d.ts +2 -3
  4. package/lib/cjs/agents/mcp-agent.js +10 -6
  5. package/lib/cjs/execution-engine/execution-engine.js +1 -1
  6. package/lib/cjs/loader/agent-js.js +1 -1
  7. package/lib/cjs/loader/agent-yaml.d.ts +1 -0
  8. package/lib/cjs/loader/agent-yaml.js +4 -0
  9. package/lib/cjs/loader/index.d.ts +72 -1
  10. package/lib/cjs/loader/index.js +29 -13
  11. package/lib/cjs/models/claude-chat-model.js +1 -1
  12. package/lib/cjs/models/deepseek-chat-model.d.ts +7 -0
  13. package/lib/cjs/models/deepseek-chat-model.js +19 -0
  14. package/lib/cjs/models/gemini-chat-model.d.ts +8 -0
  15. package/lib/cjs/models/gemini-chat-model.js +20 -0
  16. package/lib/cjs/models/ollama-chat-model.d.ts +6 -0
  17. package/lib/cjs/models/ollama-chat-model.js +18 -0
  18. package/lib/cjs/models/open-router-chat-model.d.ts +5 -0
  19. package/lib/cjs/models/open-router-chat-model.js +17 -0
  20. package/lib/cjs/models/openai-chat-model.d.ts +23 -1
  21. package/lib/cjs/models/openai-chat-model.js +182 -78
  22. package/lib/cjs/models/xai-chat-model.d.ts +3 -11
  23. package/lib/cjs/models/xai-chat-model.js +1 -14
  24. package/lib/cjs/prompt/prompt-builder.js +3 -0
  25. package/lib/cjs/utils/prompts.d.ts +1 -0
  26. package/lib/cjs/utils/prompts.js +13 -0
  27. package/lib/cjs/utils/type-utils.d.ts +1 -1
  28. package/lib/cjs/utils/type-utils.js +1 -1
  29. package/lib/dts/agents/mcp-agent.d.ts +2 -3
  30. package/lib/dts/loader/agent-yaml.d.ts +1 -0
  31. package/lib/dts/loader/index.d.ts +72 -1
  32. package/lib/dts/models/deepseek-chat-model.d.ts +7 -0
  33. package/lib/dts/models/gemini-chat-model.d.ts +8 -0
  34. package/lib/dts/models/ollama-chat-model.d.ts +6 -0
  35. package/lib/dts/models/open-router-chat-model.d.ts +5 -0
  36. package/lib/dts/models/openai-chat-model.d.ts +23 -1
  37. package/lib/dts/models/xai-chat-model.d.ts +3 -11
  38. package/lib/dts/utils/prompts.d.ts +1 -0
  39. package/lib/dts/utils/type-utils.d.ts +1 -1
  40. package/lib/esm/agents/agent.js +3 -3
  41. package/lib/esm/agents/mcp-agent.d.ts +2 -3
  42. package/lib/esm/agents/mcp-agent.js +10 -6
  43. package/lib/esm/execution-engine/execution-engine.js +1 -1
  44. package/lib/esm/loader/agent-js.js +1 -1
  45. package/lib/esm/loader/agent-yaml.d.ts +1 -0
  46. package/lib/esm/loader/agent-yaml.js +4 -0
  47. package/lib/esm/loader/index.d.ts +72 -1
  48. package/lib/esm/loader/index.js +28 -13
  49. package/lib/esm/models/claude-chat-model.js +1 -1
  50. package/lib/esm/models/deepseek-chat-model.d.ts +7 -0
  51. package/lib/esm/models/deepseek-chat-model.js +15 -0
  52. package/lib/esm/models/gemini-chat-model.d.ts +8 -0
  53. package/lib/esm/models/gemini-chat-model.js +16 -0
  54. package/lib/esm/models/ollama-chat-model.d.ts +6 -0
  55. package/lib/esm/models/ollama-chat-model.js +14 -0
  56. package/lib/esm/models/open-router-chat-model.d.ts +5 -0
  57. package/lib/esm/models/open-router-chat-model.js +13 -0
  58. package/lib/esm/models/openai-chat-model.d.ts +23 -1
  59. package/lib/esm/models/openai-chat-model.js +178 -78
  60. package/lib/esm/models/xai-chat-model.d.ts +3 -11
  61. package/lib/esm/models/xai-chat-model.js +1 -11
  62. package/lib/esm/prompt/prompt-builder.js +3 -0
  63. package/lib/esm/utils/prompts.d.ts +1 -0
  64. package/lib/esm/utils/prompts.js +10 -0
  65. package/lib/esm/utils/type-utils.d.ts +1 -1
  66. package/lib/esm/utils/type-utils.js +1 -1
  67. package/package.json +6 -3
@@ -3,11 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OpenAIChatModel = exports.openAIChatModelOptionsSchema = void 0;
6
+ exports.ROLE_MAP = exports.OpenAIChatModel = exports.openAIChatModelOptionsSchema = void 0;
7
+ exports.contentsFromInputMessages = contentsFromInputMessages;
8
+ exports.toolsFromInputTools = toolsFromInputTools;
9
+ exports.jsonSchemaToOpenAIJsonSchema = jsonSchemaToOpenAIJsonSchema;
10
+ exports.extractResultFromStream = extractResultFromStream;
7
11
  const nanoid_1 = require("nanoid");
8
12
  const openai_1 = __importDefault(require("openai"));
9
13
  const zod_1 = require("zod");
10
14
  const json_schema_js_1 = require("../utils/json-schema.js");
15
+ const model_utils_js_1 = require("../utils/model-utils.js");
16
+ const prompts_js_1 = require("../utils/prompts.js");
11
17
  const type_utils_js_1 = require("../utils/type-utils.js");
12
18
  const chat_model_js_1 = require("./chat-model.js");
13
19
  const CHAT_MODEL_OPENAI_DEFAULT_MODEL = "gpt-4o-mini";
@@ -29,16 +35,23 @@ exports.openAIChatModelOptionsSchema = zod_1.z.object({
29
35
  class OpenAIChatModel extends chat_model_js_1.ChatModel {
30
36
  options;
31
37
  constructor(options) {
32
- if (options)
33
- (0, type_utils_js_1.checkArguments)("OpenAIChatModel", exports.openAIChatModelOptionsSchema, options);
34
38
  super();
35
39
  this.options = options;
40
+ if (options)
41
+ (0, type_utils_js_1.checkArguments)(this.name, exports.openAIChatModelOptionsSchema, options);
36
42
  }
37
43
  _client;
44
+ apiKeyEnvName = "OPENAI_API_KEY";
45
+ apiKeyDefault;
46
+ supportsNativeStructuredOutputs = true;
47
+ supportsEndWithSystemMessage = true;
48
+ supportsToolsUseWithJsonSchema = true;
49
+ supportsParallelToolCalls = true;
50
+ supportsToolsEmptyParameters = true;
38
51
  get client() {
39
- const apiKey = this.options?.apiKey || process.env.OPENAI_API_KEY;
52
+ const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault;
40
53
  if (!apiKey)
41
- throw new Error("Api Key is required for OpenAIChatModel");
54
+ throw new Error(`Api Key is required for ${this.name}`);
42
55
  this._client ??= new openai_1.default({
43
56
  baseURL: this.options?.baseURL,
44
57
  apiKey,
@@ -49,86 +62,99 @@ class OpenAIChatModel extends chat_model_js_1.ChatModel {
49
62
  return this.options?.modelOptions;
50
63
  }
51
64
  async process(input) {
52
- const res = await this.client.chat.completions.create({
65
+ const body = {
53
66
  model: this.options?.model || CHAT_MODEL_OPENAI_DEFAULT_MODEL,
54
67
  temperature: input.modelOptions?.temperature ?? this.modelOptions?.temperature,
55
68
  top_p: input.modelOptions?.topP ?? this.modelOptions?.topP,
56
69
  frequency_penalty: input.modelOptions?.frequencyPenalty ?? this.modelOptions?.frequencyPenalty,
57
70
  presence_penalty: input.modelOptions?.presencePenalty ?? this.modelOptions?.presencePenalty,
58
- messages: await contentsFromInputMessages(input.messages),
59
- tools: toolsFromInputTools(input.tools),
60
- tool_choice: input.toolChoice,
61
- parallel_tool_calls: !input.tools?.length
62
- ? undefined
63
- : (input.modelOptions?.parallelToolCalls ?? this.modelOptions?.parallelToolCalls),
64
- response_format: input.responseFormat?.type === "json_schema"
65
- ? {
66
- type: "json_schema",
67
- json_schema: {
68
- ...input.responseFormat.jsonSchema,
69
- schema: jsonSchemaToOpenAIJsonSchema(input.responseFormat.jsonSchema.schema),
70
- },
71
- }
72
- : undefined,
71
+ messages: await this.getRunMessages(input),
73
72
  stream_options: {
74
73
  include_usage: true,
75
74
  },
76
75
  stream: true,
76
+ };
77
+ const { jsonMode, responseFormat } = await this.getRunResponseFormat(input);
78
+ const stream = await this.client.chat.completions.create({
79
+ ...body,
80
+ tools: toolsFromInputTools(input.tools, {
81
+ addTypeToEmptyParameters: !this.supportsToolsEmptyParameters,
82
+ }),
83
+ tool_choice: input.toolChoice,
84
+ parallel_tool_calls: this.getParallelToolCalls(input),
85
+ response_format: responseFormat,
77
86
  });
78
- let text = "";
79
- const toolCalls = [];
80
- let usage;
81
- let model;
82
- for await (const chunk of res) {
83
- const choice = chunk.choices?.[0];
84
- model ??= chunk.model;
85
- if (choice?.delta.tool_calls?.length) {
86
- for (const call of choice.delta.tool_calls) {
87
- toolCalls[call.index] ??= {
88
- id: call.id || (0, nanoid_1.nanoid)(),
89
- type: "function",
90
- function: { name: "", arguments: {} },
91
- args: "",
92
- };
93
- const c = toolCalls[call.index];
94
- if (!c)
95
- throw new Error("Tool call not found");
96
- if (call.type)
97
- c.type = call.type;
98
- c.function.name = c.function.name + (call.function?.name || "");
99
- c.args = c.args.concat(call.function?.arguments || "");
100
- }
101
- }
102
- if (choice?.delta.content)
103
- text += choice.delta.content;
104
- if (chunk.usage) {
105
- usage = {
106
- inputTokens: chunk.usage.prompt_tokens,
107
- outputTokens: chunk.usage.completion_tokens,
108
- };
109
- }
87
+ const result = await extractResultFromStream(stream, jsonMode);
88
+ if (!this.supportsToolsUseWithJsonSchema &&
89
+ !result.toolCalls?.length &&
90
+ input.responseFormat?.type === "json_schema" &&
91
+ result.text) {
92
+ const output = await this.requestStructuredOutput(body, input.responseFormat);
93
+ return { ...output, usage: (0, model_utils_js_1.mergeUsage)(result.usage, output.usage) };
110
94
  }
111
- const result = {
112
- usage,
113
- model,
114
- };
115
- if (input.responseFormat?.type === "json_schema" && text) {
116
- result.json = (0, json_schema_js_1.parseJSON)(text);
95
+ return result;
96
+ }
97
+ getParallelToolCalls(input) {
98
+ if (!this.supportsParallelToolCalls)
99
+ return undefined;
100
+ if (!input.tools?.length)
101
+ return undefined;
102
+ return input.modelOptions?.parallelToolCalls ?? this.modelOptions?.parallelToolCalls;
103
+ }
104
+ async getRunMessages(input) {
105
+ const messages = await contentsFromInputMessages(input.messages);
106
+ if (!this.supportsEndWithSystemMessage && messages.at(-1)?.role !== "user") {
107
+ messages.push({ role: "user", content: "" });
117
108
  }
118
- else {
119
- result.text = text;
109
+ if (!this.supportsToolsUseWithJsonSchema && input.tools?.length)
110
+ return messages;
111
+ if (this.supportsNativeStructuredOutputs)
112
+ return messages;
113
+ if (input.responseFormat?.type === "json_schema") {
114
+ messages.unshift({
115
+ role: "system",
116
+ content: (0, prompts_js_1.getJsonOutputPrompt)(input.responseFormat.jsonSchema.schema),
117
+ });
120
118
  }
121
- if (toolCalls.length) {
122
- result.toolCalls = toolCalls.map(({ args, ...c }) => ({
123
- ...c,
124
- function: { ...c.function, arguments: (0, json_schema_js_1.parseJSON)(args) },
125
- }));
119
+ return messages;
120
+ }
121
+ async getRunResponseFormat(input) {
122
+ if (!this.supportsToolsUseWithJsonSchema && input.tools?.length)
123
+ return { jsonMode: false, responseFormat: undefined };
124
+ if (!this.supportsNativeStructuredOutputs) {
125
+ const jsonMode = input.responseFormat?.type === "json_schema";
126
+ return { jsonMode, responseFormat: jsonMode ? { type: "json_object" } : undefined };
126
127
  }
127
- return result;
128
+ if (input.responseFormat?.type === "json_schema") {
129
+ return {
130
+ jsonMode: true,
131
+ responseFormat: {
132
+ type: "json_schema",
133
+ json_schema: {
134
+ ...input.responseFormat.jsonSchema,
135
+ schema: jsonSchemaToOpenAIJsonSchema(input.responseFormat.jsonSchema.schema),
136
+ },
137
+ },
138
+ };
139
+ }
140
+ return { jsonMode: false, responseFormat: undefined };
141
+ }
142
+ async requestStructuredOutput(body, responseFormat) {
143
+ if (responseFormat?.type !== "json_schema") {
144
+ throw new Error("Expected json_schema response format");
145
+ }
146
+ const { jsonMode, responseFormat: resolvedResponseFormat } = await this.getRunResponseFormat({
147
+ responseFormat,
148
+ });
149
+ const res = await this.client.chat.completions.create({
150
+ ...body,
151
+ response_format: resolvedResponseFormat,
152
+ });
153
+ return extractResultFromStream(res, jsonMode);
128
154
  }
129
155
  }
130
156
  exports.OpenAIChatModel = OpenAIChatModel;
131
- const ROLE_MAP = {
157
+ exports.ROLE_MAP = {
132
158
  system: "system",
133
159
  user: "user",
134
160
  agent: "assistant",
@@ -136,7 +162,7 @@ const ROLE_MAP = {
136
162
  };
137
163
  async function contentsFromInputMessages(messages) {
138
164
  return messages.map((i) => ({
139
- role: ROLE_MAP[i.role],
165
+ role: exports.ROLE_MAP[i.role],
140
166
  content: typeof i.content === "string"
141
167
  ? i.content
142
168
  : i.content
@@ -163,16 +189,22 @@ async function contentsFromInputMessages(messages) {
163
189
  name: i.name,
164
190
  }));
165
191
  }
166
- function toolsFromInputTools(tools) {
192
+ function toolsFromInputTools(tools, options) {
167
193
  return tools?.length
168
- ? tools.map((i) => ({
169
- type: "function",
170
- function: {
171
- name: i.function.name,
172
- description: i.function.description,
173
- parameters: i.function.parameters,
174
- },
175
- }))
194
+ ? tools.map((i) => {
195
+ const parameters = i.function.parameters;
196
+ if (options?.addTypeToEmptyParameters && Object.keys(parameters).length === 0) {
197
+ parameters.type = "object";
198
+ }
199
+ return {
200
+ type: "function",
201
+ function: {
202
+ name: i.function.name,
203
+ description: i.function.description,
204
+ parameters,
205
+ },
206
+ };
207
+ })
176
208
  : undefined;
177
209
  }
178
210
  function jsonSchemaToOpenAIJsonSchema(schema) {
@@ -200,3 +232,75 @@ function jsonSchemaToOpenAIJsonSchema(schema) {
200
232
  }
201
233
  return schema;
202
234
  }
235
+ async function extractResultFromStream(stream, jsonMode = false) {
236
+ let text = "";
237
+ const toolCalls = [];
238
+ let usage;
239
+ let model;
240
+ for await (const chunk of stream) {
241
+ const choice = chunk.choices?.[0];
242
+ model ??= chunk.model;
243
+ if (choice?.delta.tool_calls?.length) {
244
+ for (const call of choice.delta.tool_calls) {
245
+ // Gemini not support tool call delta
246
+ if (call.index !== undefined) {
247
+ handleToolCallDelta(toolCalls, call);
248
+ }
249
+ else {
250
+ handleCompleteToolCall(toolCalls, call);
251
+ }
252
+ }
253
+ }
254
+ if (choice?.delta.content)
255
+ text += choice.delta.content;
256
+ if (chunk.usage) {
257
+ usage = {
258
+ inputTokens: chunk.usage.prompt_tokens,
259
+ outputTokens: chunk.usage.completion_tokens,
260
+ };
261
+ }
262
+ }
263
+ const result = {
264
+ usage,
265
+ model,
266
+ };
267
+ if (jsonMode && text) {
268
+ result.json = (0, json_schema_js_1.parseJSON)(text);
269
+ }
270
+ else {
271
+ result.text = text;
272
+ }
273
+ if (toolCalls.length) {
274
+ result.toolCalls = toolCalls.map(({ args, ...c }) => ({
275
+ ...c,
276
+ function: { ...c.function, arguments: (0, json_schema_js_1.parseJSON)(args) },
277
+ }));
278
+ }
279
+ return result;
280
+ }
281
+ function handleToolCallDelta(toolCalls, call) {
282
+ toolCalls[call.index] ??= {
283
+ id: call.id || (0, nanoid_1.nanoid)(),
284
+ type: "function",
285
+ function: { name: "", arguments: {} },
286
+ args: "",
287
+ };
288
+ const c = toolCalls[call.index];
289
+ if (!c)
290
+ throw new Error("Tool call not found");
291
+ if (call.type)
292
+ c.type = call.type;
293
+ c.function.name = c.function.name + (call.function?.name || "");
294
+ c.args = c.args.concat(call.function?.arguments || "");
295
+ }
296
+ function handleCompleteToolCall(toolCalls, call) {
297
+ toolCalls.push({
298
+ id: call.id || (0, nanoid_1.nanoid)(),
299
+ type: "function",
300
+ function: {
301
+ name: call.function?.name || "",
302
+ arguments: (0, json_schema_js_1.parseJSON)(call.function?.arguments || "{}"),
303
+ },
304
+ args: call.function?.arguments || "",
305
+ });
306
+ }
@@ -1,13 +1,5 @@
1
- import OpenAI from "openai";
2
- import type { ChatModelOptions } from "./chat-model.js";
3
- import { OpenAIChatModel } from "./openai-chat-model.js";
4
- export interface XAIChatModelOptions {
5
- apiKey?: string;
6
- model?: string;
7
- modelOptions?: ChatModelOptions;
8
- baseURL?: string;
9
- }
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
10
2
  export declare class XAIChatModel extends OpenAIChatModel {
11
- constructor(options?: XAIChatModelOptions);
12
- get client(): OpenAI;
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
13
5
  }
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.XAIChatModel = void 0;
7
- const openai_1 = __importDefault(require("openai"));
8
4
  const openai_chat_model_js_1 = require("./openai-chat-model.js");
9
5
  const XAI_DEFAULT_CHAT_MODEL = "grok-2-latest";
10
6
  const XAI_BASE_URL = "https://api.x.ai/v1";
@@ -16,15 +12,6 @@ class XAIChatModel extends openai_chat_model_js_1.OpenAIChatModel {
16
12
  baseURL: options?.baseURL || XAI_BASE_URL,
17
13
  });
18
14
  }
19
- get client() {
20
- const apiKey = this.options?.apiKey || process.env.XAI_API_KEY;
21
- if (!apiKey)
22
- throw new Error("Api Key is required for XAIChatModel");
23
- this._client ??= new openai_1.default({
24
- baseURL: this.options?.baseURL,
25
- apiKey,
26
- });
27
- return this._client;
28
- }
15
+ apiKeyEnvName = "XAI_API_KEY";
29
16
  }
30
17
  exports.XAIChatModel = XAIChatModel;
@@ -132,6 +132,7 @@ class PromptBuilder {
132
132
  },
133
133
  }));
134
134
  let toolChoice;
135
+ const modelOptions = {};
135
136
  // use manual choice if configured in the agent
136
137
  const manualChoice = options.agent?.toolChoice;
137
138
  if (manualChoice) {
@@ -146,6 +147,7 @@ class PromptBuilder {
146
147
  }
147
148
  else if (manualChoice === "router") {
148
149
  toolChoice = "required";
150
+ modelOptions.parallelToolCalls = false;
149
151
  }
150
152
  else {
151
153
  toolChoice = manualChoice;
@@ -159,6 +161,7 @@ class PromptBuilder {
159
161
  toolAgents: toolAgents.length ? toolAgents : undefined,
160
162
  tools: tools.length ? tools : undefined,
161
163
  toolChoice,
164
+ modelOptions: Object.keys(modelOptions).length ? modelOptions : undefined,
162
165
  };
163
166
  }
164
167
  }
@@ -0,0 +1 @@
1
+ export declare function getJsonOutputPrompt(schema: Record<string, unknown> | string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJsonOutputPrompt = getJsonOutputPrompt;
4
+ function getJsonOutputPrompt(schema) {
5
+ let prompt = "Provide your output as a JSON containing the following fields:";
6
+ if (typeof schema === "string") {
7
+ prompt += `\n<json_fields>\n${schema}\n</json_fields>`;
8
+ }
9
+ else {
10
+ prompt += `\n<json_fields>\n${JSON.stringify(schema)}\n</json_fields>`;
11
+ }
12
+ return prompt;
13
+ }
@@ -11,5 +11,5 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
11
11
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
12
12
  [key: string]: T;
13
13
  };
14
- export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): void;
14
+ export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): T;
15
15
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;
@@ -54,7 +54,7 @@ function createAccessorArray(array, accessor) {
54
54
  }
55
55
  function checkArguments(prefix, schema, args) {
56
56
  try {
57
- schema.parse(args, {
57
+ return schema.parse(args, {
58
58
  errorMap: (issue, ctx) => {
59
59
  if (issue.code === "invalid_union") {
60
60
  // handle all issues that are not invalid_type
@@ -22,7 +22,7 @@ export type SSEServerParameters = {
22
22
  opts?: SSEClientTransportOptions;
23
23
  /**
24
24
  * The timeout for requests to the server, in milliseconds.
25
- * @default 10000
25
+ * @default 60000
26
26
  */
27
27
  timeout?: number;
28
28
  /**
@@ -41,7 +41,7 @@ export declare class MCPAgent extends Agent {
41
41
  static from(options: MCPAgentOptions): MCPAgent;
42
42
  private static fromTransport;
43
43
  constructor(options: MCPAgentOptions);
44
- private client;
44
+ client: Client;
45
45
  readonly prompts: MCPPrompt[] & {
46
46
  [key: string]: MCPPrompt;
47
47
  };
@@ -71,7 +71,6 @@ export interface MCPBaseOptions<I extends Message = Message, O extends Message =
71
71
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
72
72
  constructor(options: MCPBaseOptions<I, O>);
73
73
  protected client: ClientWithReconnect;
74
- protected get mcpServer(): string | undefined;
75
74
  }
76
75
  export declare class MCPTool extends MCPBase<Message, CallToolResult> {
77
76
  process(input: Message): Promise<CallToolResult>;
@@ -10,6 +10,7 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
10
10
  }, {
11
11
  [x: string]: any;
12
12
  }> | undefined;
13
+ tool_choice?: "auto" | "none" | "required" | "router" | undefined;
13
14
  output_schema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
14
15
  [x: string]: any;
15
16
  }, {
@@ -1,5 +1,6 @@
1
+ import { z } from "zod";
1
2
  import { type Agent } from "../agents/agent.js";
2
- import type { ChatModel } from "../models/chat-model.js";
3
+ import type { ChatModel, ChatModelOptions } from "../models/chat-model.js";
3
4
  export interface LoadOptions {
4
5
  path: string;
5
6
  }
@@ -19,6 +20,75 @@ export declare function load(options: LoadOptions): Promise<{
19
20
  } | null | undefined;
20
21
  }>;
21
22
  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>;
24
+ declare const aigneFileSchema: z.ZodObject<{
25
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
+ chat_model: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodObject<{
28
+ provider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ temperature: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
31
+ top_p: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
32
+ frequent_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
33
+ presence_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ name?: string | null | undefined;
36
+ temperature?: number | null | undefined;
37
+ provider?: string | null | undefined;
38
+ top_p?: number | null | undefined;
39
+ frequent_penalty?: number | null | undefined;
40
+ presence_penalty?: number | null | undefined;
41
+ }, {
42
+ name?: string | null | undefined;
43
+ temperature?: number | null | undefined;
44
+ provider?: string | null | undefined;
45
+ top_p?: number | null | undefined;
46
+ frequent_penalty?: number | null | undefined;
47
+ presence_penalty?: number | null | undefined;
48
+ }>]>>>, {
49
+ name?: string | null | undefined;
50
+ temperature?: number | null | undefined;
51
+ provider?: string | null | undefined;
52
+ top_p?: number | null | undefined;
53
+ frequent_penalty?: number | null | undefined;
54
+ presence_penalty?: number | null | undefined;
55
+ } | null | undefined, string | {
56
+ name?: string | null | undefined;
57
+ temperature?: number | null | undefined;
58
+ provider?: string | null | undefined;
59
+ top_p?: number | null | undefined;
60
+ frequent_penalty?: number | null | undefined;
61
+ presence_penalty?: number | null | undefined;
62
+ } | null | undefined>;
63
+ agents: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
64
+ tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ description?: string | null | undefined;
67
+ tools?: string[] | null | undefined;
68
+ name?: string | null | undefined;
69
+ chat_model?: {
70
+ name?: string | null | undefined;
71
+ temperature?: number | null | undefined;
72
+ provider?: string | null | undefined;
73
+ top_p?: number | null | undefined;
74
+ frequent_penalty?: number | null | undefined;
75
+ presence_penalty?: number | null | undefined;
76
+ } | null | undefined;
77
+ agents?: string[] | null | undefined;
78
+ }, {
79
+ description?: string | null | undefined;
80
+ tools?: string[] | null | undefined;
81
+ name?: string | null | undefined;
82
+ chat_model?: string | {
83
+ name?: string | null | undefined;
84
+ temperature?: number | null | undefined;
85
+ provider?: string | null | undefined;
86
+ top_p?: number | null | undefined;
87
+ frequent_penalty?: number | null | undefined;
88
+ presence_penalty?: number | null | undefined;
89
+ } | null | undefined;
90
+ agents?: string[] | null | undefined;
91
+ }>;
22
92
  export declare function loadAIGNEFile(path: string): Promise<{
23
93
  description?: string | null | undefined;
24
94
  tools?: string[] | null | undefined;
@@ -33,3 +103,4 @@ export declare function loadAIGNEFile(path: string): Promise<{
33
103
  } | null | undefined;
34
104
  agents?: string[] | null | undefined;
35
105
  }>;
106
+ export {};
@@ -0,0 +1,7 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ export declare class DeepSeekChatModel extends OpenAIChatModel {
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
5
+ protected supportsNativeStructuredOutputs: boolean;
6
+ protected supportsToolsEmptyParameters: boolean;
7
+ }
@@ -0,0 +1,8 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ export declare class GeminiChatModel extends OpenAIChatModel {
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
5
+ protected supportsEndWithSystemMessage: boolean;
6
+ protected supportsToolsUseWithJsonSchema: boolean;
7
+ protected supportsParallelToolCalls: boolean;
8
+ }
@@ -0,0 +1,6 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ export declare class OllamaChatModel extends OpenAIChatModel {
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
5
+ protected apiKeyDefault: string;
6
+ }
@@ -0,0 +1,5 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
2
+ export declare class OpenRouterChatModel extends OpenAIChatModel {
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
5
+ }
@@ -1,6 +1,8 @@
1
1
  import OpenAI from "openai";
2
+ import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
3
+ import type { Stream } from "openai/streaming.js";
2
4
  import { z } from "zod";
3
- import { ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "./chat-model.js";
5
+ import { ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "./chat-model.js";
4
6
  export interface OpenAIChatModelOptions {
5
7
  apiKey?: string;
6
8
  baseURL?: string;
@@ -62,7 +64,27 @@ export declare class OpenAIChatModel extends ChatModel {
62
64
  options?: OpenAIChatModelOptions | undefined;
63
65
  constructor(options?: OpenAIChatModelOptions | undefined);
64
66
  protected _client?: OpenAI;
67
+ protected apiKeyEnvName: string;
68
+ protected apiKeyDefault: string | undefined;
69
+ protected supportsNativeStructuredOutputs: boolean;
70
+ protected supportsEndWithSystemMessage: boolean;
71
+ protected supportsToolsUseWithJsonSchema: boolean;
72
+ protected supportsParallelToolCalls: boolean;
73
+ protected supportsToolsEmptyParameters: boolean;
65
74
  get client(): OpenAI;
66
75
  get modelOptions(): ChatModelOptions | undefined;
67
76
  process(input: ChatModelInput): Promise<ChatModelOutput>;
77
+ private getParallelToolCalls;
78
+ private getRunMessages;
79
+ private getRunResponseFormat;
80
+ private requestStructuredOutput;
68
81
  }
82
+ export declare const ROLE_MAP: {
83
+ [key in Role]: ChatCompletionMessageParam["role"];
84
+ };
85
+ export declare function contentsFromInputMessages(messages: ChatModelInputMessage[]): Promise<ChatCompletionMessageParam[]>;
86
+ export declare function toolsFromInputTools(tools?: ChatModelInputTool[], options?: {
87
+ addTypeToEmptyParameters?: boolean;
88
+ }): ChatCompletionTool[] | undefined;
89
+ export declare function jsonSchemaToOpenAIJsonSchema(schema: Record<string, unknown>): Record<string, unknown>;
90
+ export declare function extractResultFromStream(stream: Stream<OpenAI.Chat.Completions.ChatCompletionChunk>, jsonMode?: boolean): Promise<ChatModelOutput>;
@@ -1,13 +1,5 @@
1
- import OpenAI from "openai";
2
- import type { ChatModelOptions } from "./chat-model.js";
3
- import { OpenAIChatModel } from "./openai-chat-model.js";
4
- export interface XAIChatModelOptions {
5
- apiKey?: string;
6
- model?: string;
7
- modelOptions?: ChatModelOptions;
8
- baseURL?: string;
9
- }
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai-chat-model.js";
10
2
  export declare class XAIChatModel extends OpenAIChatModel {
11
- constructor(options?: XAIChatModelOptions);
12
- get client(): OpenAI;
3
+ constructor(options?: OpenAIChatModelOptions);
4
+ protected apiKeyEnvName: string;
13
5
  }
@@ -0,0 +1 @@
1
+ export declare function getJsonOutputPrompt(schema: Record<string, unknown> | string): string;
@@ -11,5 +11,5 @@ export declare function orArrayToArray<T>(value?: T | T[]): T[];
11
11
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
12
12
  [key: string]: T;
13
13
  };
14
- export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): void;
14
+ export declare function checkArguments<T>(prefix: string, schema: ZodType<T>, args: T): T;
15
15
  export declare function tryOrThrow<P extends PromiseOrValue<unknown>>(fn: () => P, error: string | Error | ((error: Error) => Error)): P;