@aigne/core 1.8.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 (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/cjs/agents/agent.js +2 -2
  3. package/lib/cjs/loader/index.js +20 -4
  4. package/lib/cjs/models/deepseek-chat-model.d.ts +7 -0
  5. package/lib/cjs/models/deepseek-chat-model.js +19 -0
  6. package/lib/cjs/models/gemini-chat-model.d.ts +8 -0
  7. package/lib/cjs/models/gemini-chat-model.js +20 -0
  8. package/lib/cjs/models/ollama-chat-model.d.ts +6 -0
  9. package/lib/cjs/models/ollama-chat-model.js +18 -0
  10. package/lib/cjs/models/open-router-chat-model.d.ts +5 -0
  11. package/lib/cjs/models/open-router-chat-model.js +17 -0
  12. package/lib/cjs/models/openai-chat-model.d.ts +23 -1
  13. package/lib/cjs/models/openai-chat-model.js +182 -78
  14. package/lib/cjs/models/xai-chat-model.d.ts +3 -11
  15. package/lib/cjs/models/xai-chat-model.js +1 -14
  16. package/lib/cjs/prompt/prompt-builder.js +3 -0
  17. package/lib/cjs/utils/prompts.d.ts +1 -0
  18. package/lib/cjs/utils/prompts.js +13 -0
  19. package/lib/cjs/utils/type-utils.d.ts +1 -1
  20. package/lib/cjs/utils/type-utils.js +1 -1
  21. package/lib/dts/models/deepseek-chat-model.d.ts +7 -0
  22. package/lib/dts/models/gemini-chat-model.d.ts +8 -0
  23. package/lib/dts/models/ollama-chat-model.d.ts +6 -0
  24. package/lib/dts/models/open-router-chat-model.d.ts +5 -0
  25. package/lib/dts/models/openai-chat-model.d.ts +23 -1
  26. package/lib/dts/models/xai-chat-model.d.ts +3 -11
  27. package/lib/dts/utils/prompts.d.ts +1 -0
  28. package/lib/dts/utils/type-utils.d.ts +1 -1
  29. package/lib/esm/agents/agent.js +3 -3
  30. package/lib/esm/loader/index.js +20 -4
  31. package/lib/esm/models/deepseek-chat-model.d.ts +7 -0
  32. package/lib/esm/models/deepseek-chat-model.js +15 -0
  33. package/lib/esm/models/gemini-chat-model.d.ts +8 -0
  34. package/lib/esm/models/gemini-chat-model.js +16 -0
  35. package/lib/esm/models/ollama-chat-model.d.ts +6 -0
  36. package/lib/esm/models/ollama-chat-model.js +14 -0
  37. package/lib/esm/models/open-router-chat-model.d.ts +5 -0
  38. package/lib/esm/models/open-router-chat-model.js +13 -0
  39. package/lib/esm/models/openai-chat-model.d.ts +23 -1
  40. package/lib/esm/models/openai-chat-model.js +178 -78
  41. package/lib/esm/models/xai-chat-model.d.ts +3 -11
  42. package/lib/esm/models/xai-chat-model.js +1 -11
  43. package/lib/esm/prompt/prompt-builder.js +3 -0
  44. package/lib/esm/utils/prompts.d.ts +1 -0
  45. package/lib/esm/utils/prompts.js +10 -0
  46. package/lib/esm/utils/type-utils.d.ts +1 -1
  47. package/lib/esm/utils/type-utils.js +1 -1
  48. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- import OpenAI from "openai";
2
1
  import { OpenAIChatModel } from "./openai-chat-model.js";
3
2
  const XAI_DEFAULT_CHAT_MODEL = "grok-2-latest";
4
3
  const XAI_BASE_URL = "https://api.x.ai/v1";
@@ -10,14 +9,5 @@ export class XAIChatModel extends OpenAIChatModel {
10
9
  baseURL: options?.baseURL || XAI_BASE_URL,
11
10
  });
12
11
  }
13
- get client() {
14
- const apiKey = this.options?.apiKey || process.env.XAI_API_KEY;
15
- if (!apiKey)
16
- throw new Error("Api Key is required for XAIChatModel");
17
- this._client ??= new OpenAI({
18
- baseURL: this.options?.baseURL,
19
- apiKey,
20
- });
21
- return this._client;
22
- }
12
+ apiKeyEnvName = "XAI_API_KEY";
23
13
  }
@@ -127,6 +127,7 @@ export class PromptBuilder {
127
127
  },
128
128
  }));
129
129
  let toolChoice;
130
+ const modelOptions = {};
130
131
  // use manual choice if configured in the agent
131
132
  const manualChoice = options.agent?.toolChoice;
132
133
  if (manualChoice) {
@@ -141,6 +142,7 @@ export class PromptBuilder {
141
142
  }
142
143
  else if (manualChoice === "router") {
143
144
  toolChoice = "required";
145
+ modelOptions.parallelToolCalls = false;
144
146
  }
145
147
  else {
146
148
  toolChoice = manualChoice;
@@ -154,6 +156,7 @@ export class PromptBuilder {
154
156
  toolAgents: toolAgents.length ? toolAgents : undefined,
155
157
  tools: tools.length ? tools : undefined,
156
158
  toolChoice,
159
+ modelOptions: Object.keys(modelOptions).length ? modelOptions : undefined,
157
160
  };
158
161
  }
159
162
  }
@@ -0,0 +1 @@
1
+ export declare function getJsonOutputPrompt(schema: Record<string, unknown> | string): string;
@@ -0,0 +1,10 @@
1
+ export function getJsonOutputPrompt(schema) {
2
+ let prompt = "Provide your output as a JSON containing the following fields:";
3
+ if (typeof schema === "string") {
4
+ prompt += `\n<json_fields>\n${schema}\n</json_fields>`;
5
+ }
6
+ else {
7
+ prompt += `\n<json_fields>\n${JSON.stringify(schema)}\n</json_fields>`;
8
+ }
9
+ return prompt;
10
+ }
@@ -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;
@@ -43,7 +43,7 @@ export function createAccessorArray(array, accessor) {
43
43
  }
44
44
  export function checkArguments(prefix, schema, args) {
45
45
  try {
46
- schema.parse(args, {
46
+ return schema.parse(args, {
47
47
  errorMap: (issue, ctx) => {
48
48
  if (issue.code === "invalid_union") {
49
49
  // handle all issues that are not invalid_type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"