@aigne/openai 0.10.9 → 0.10.11

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.10.11](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.10.10...openai-v0.10.11) (2025-08-05)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * call tools args is null ([#313](https://github.com/AIGNE-io/aigne-framework/issues/313)) ([2cf9487](https://github.com/AIGNE-io/aigne-framework/commit/2cf9487b606cb7884086938def834f89a3c3a775))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.43.1
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.19
18
+
19
+ ## [0.10.10](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.10.9...openai-v0.10.10) (2025-08-04)
20
+
21
+
22
+ ### Dependencies
23
+
24
+ * The following workspace dependencies were updated
25
+ * dependencies
26
+ * @aigne/core bumped to 1.43.0
27
+ * devDependencies
28
+ * @aigne/test-utils bumped to 0.5.18
29
+
3
30
  ## [0.10.9](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.10.8...openai-v0.10.9) (2025-08-01)
4
31
 
5
32
 
package/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @aigne/openai
2
2
 
3
+ <p align="center">
4
+ <picture>
5
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
6
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
7
+ <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
8
+ </picture>
9
+ </p>
10
+
3
11
  [![GitHub star chart](https://img.shields.io/github/stars/AIGNE-io/aigne-framework?style=flat-square)](https://star-history.com/#AIGNE-io/aigne-framework)
4
12
  [![Open Issues](https://img.shields.io/github/issues-raw/AIGNE-io/aigne-framework?style=flat-square)](https://github.com/AIGNE-io/aigne-framework/issues)
5
13
  [![codecov](https://codecov.io/gh/AIGNE-io/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/AIGNE-io/aigne-framework)
@@ -1,4 +1,4 @@
1
- import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import OpenAI, { type ClientOptions } from "openai";
4
4
  import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
@@ -147,12 +147,6 @@ export declare class OpenAIChatModel extends ChatModel {
147
147
  private requestStructuredOutput;
148
148
  private extractResultFromStream;
149
149
  }
150
- /**
151
- * @hidden
152
- */
153
- export declare const ROLE_MAP: {
154
- [key in Role]: ChatCompletionMessageParam["role"];
155
- };
156
150
  /**
157
151
  * @hidden
158
152
  */
@@ -3,7 +3,7 @@ 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.ROLE_MAP = exports.OpenAIChatModel = exports.openAIChatModelOptionsSchema = void 0;
6
+ exports.OpenAIChatModel = exports.openAIChatModelOptionsSchema = void 0;
7
7
  exports.contentsFromInputMessages = contentsFromInputMessages;
8
8
  exports.toolsFromInputTools = toolsFromInputTools;
9
9
  exports.jsonSchemaToOpenAIJsonSchema = jsonSchemaToOpenAIJsonSchema;
@@ -14,7 +14,6 @@ const prompts_js_1 = require("@aigne/core/utils/prompts.js");
14
14
  const stream_utils_js_1 = require("@aigne/core/utils/stream-utils.js");
15
15
  const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
16
16
  const ajv_1 = require("ajv");
17
- const jaison_1 = __importDefault(require("jaison"));
18
17
  const nanoid_1 = require("nanoid");
19
18
  const openai_1 = __importDefault(require("openai"));
20
19
  const zod_1 = require("zod");
@@ -145,11 +144,13 @@ class OpenAIChatModel extends core_1.ChatModel {
145
144
  return result;
146
145
  // Try to parse the text response as JSON
147
146
  // If it matches the json_schema, return it as json
148
- const json = safeParseJSON(result.text || "");
147
+ const json = (0, core_1.safeParseJSON)(result.text || "");
149
148
  if (this.ajv.validate(input.responseFormat.jsonSchema.schema, json)) {
150
149
  return { ...result, json, text: undefined };
151
150
  }
152
- logger_js_1.logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, { text: result.text });
151
+ logger_js_1.logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, {
152
+ text: result.text,
153
+ });
153
154
  const output = await this.requestStructuredOutput(body, input.responseFormat);
154
155
  return { ...output, usage: (0, model_utils_js_1.mergeUsage)(result.usage, output.usage) };
155
156
  }
@@ -280,7 +281,7 @@ class OpenAIChatModel extends core_1.ChatModel {
280
281
  controller.enqueue({
281
282
  delta: {
282
283
  json: {
283
- json: safeParseJSON(text),
284
+ json: (0, core_1.safeParseJSON)(text),
284
285
  },
285
286
  },
286
287
  });
@@ -291,7 +292,7 @@ class OpenAIChatModel extends core_1.ChatModel {
291
292
  json: {
292
293
  toolCalls: toolCalls.map(({ args, ...c }) => ({
293
294
  ...c,
294
- function: { ...c.function, arguments: safeParseJSON(args) },
295
+ function: { ...c.function, arguments: args ? (0, core_1.safeParseJSON)(args) : {} },
295
296
  })),
296
297
  },
297
298
  },
@@ -308,21 +309,14 @@ class OpenAIChatModel extends core_1.ChatModel {
308
309
  }
309
310
  }
310
311
  exports.OpenAIChatModel = OpenAIChatModel;
311
- /**
312
- * @hidden
313
- */
314
- exports.ROLE_MAP = {
315
- system: "system",
316
- user: "user",
317
- agent: "assistant",
318
- tool: "tool",
319
- };
312
+ // Create role mapper for OpenAI (uses standard mapping)
313
+ const mapRole = (0, core_1.createRoleMapper)(core_1.STANDARD_ROLE_MAP);
320
314
  /**
321
315
  * @hidden
322
316
  */
323
317
  async function contentsFromInputMessages(messages) {
324
318
  return messages.map((i) => ({
325
- role: exports.ROLE_MAP[i.role],
319
+ role: mapRole(i.role),
326
320
  content: typeof i.content === "string"
327
321
  ? i.content
328
322
  : i.content
@@ -419,7 +413,7 @@ function handleCompleteToolCall(toolCalls, call) {
419
413
  type: "function",
420
414
  function: {
421
415
  name: call.function?.name || "",
422
- arguments: safeParseJSON(call.function?.arguments || "{}"),
416
+ arguments: (0, core_1.safeParseJSON)(call.function?.arguments || "{}"),
423
417
  },
424
418
  args: call.function?.arguments || "",
425
419
  });
@@ -433,13 +427,4 @@ class CustomOpenAI extends openai_1.default {
433
427
  return super.makeStatusError(status, error, message, headers);
434
428
  }
435
429
  }
436
- function safeParseJSON(text) {
437
- if (!text)
438
- return null;
439
- try {
440
- return (0, jaison_1.default)(text);
441
- }
442
- catch {
443
- return null;
444
- }
445
- }
430
+ // safeParseJSON is now imported from @aigne/core
@@ -1,4 +1,4 @@
1
- import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import OpenAI, { type ClientOptions } from "openai";
4
4
  import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
@@ -147,12 +147,6 @@ export declare class OpenAIChatModel extends ChatModel {
147
147
  private requestStructuredOutput;
148
148
  private extractResultFromStream;
149
149
  }
150
- /**
151
- * @hidden
152
- */
153
- export declare const ROLE_MAP: {
154
- [key in Role]: ChatCompletionMessageParam["role"];
155
- };
156
150
  /**
157
151
  * @hidden
158
152
  */
@@ -1,4 +1,4 @@
1
- import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput, type Role } from "@aigne/core";
1
+ import { type AgentProcessResult, ChatModel, type ChatModelInput, type ChatModelInputMessage, type ChatModelInputTool, type ChatModelOptions, type ChatModelOutput } from "@aigne/core";
2
2
  import { type PromiseOrValue } from "@aigne/core/utils/type-utils.js";
3
3
  import OpenAI, { type ClientOptions } from "openai";
4
4
  import type { ChatCompletionMessageParam, ChatCompletionTool } from "openai/resources";
@@ -147,12 +147,6 @@ export declare class OpenAIChatModel extends ChatModel {
147
147
  private requestStructuredOutput;
148
148
  private extractResultFromStream;
149
149
  }
150
- /**
151
- * @hidden
152
- */
153
- export declare const ROLE_MAP: {
154
- [key in Role]: ChatCompletionMessageParam["role"];
155
- };
156
150
  /**
157
151
  * @hidden
158
152
  */
@@ -1,11 +1,10 @@
1
- import { ChatModel, } from "@aigne/core";
1
+ import { ChatModel, createRoleMapper, STANDARD_ROLE_MAP, safeParseJSON, } from "@aigne/core";
2
2
  import { logger } from "@aigne/core/utils/logger.js";
3
3
  import { mergeUsage } from "@aigne/core/utils/model-utils.js";
4
4
  import { getJsonOutputPrompt } from "@aigne/core/utils/prompts.js";
5
5
  import { agentResponseStreamToObject } from "@aigne/core/utils/stream-utils.js";
6
6
  import { checkArguments, isNonNullable, } from "@aigne/core/utils/type-utils.js";
7
7
  import { Ajv } from "ajv";
8
- import jaison from "jaison";
9
8
  import { nanoid } from "nanoid";
10
9
  import OpenAI from "openai";
11
10
  import { z } from "zod";
@@ -140,7 +139,9 @@ export class OpenAIChatModel extends ChatModel {
140
139
  if (this.ajv.validate(input.responseFormat.jsonSchema.schema, json)) {
141
140
  return { ...result, json, text: undefined };
142
141
  }
143
- logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, { text: result.text });
142
+ logger.warn(`${this.name}: Text response does not match JSON schema, trying to use tool to extract json `, {
143
+ text: result.text,
144
+ });
144
145
  const output = await this.requestStructuredOutput(body, input.responseFormat);
145
146
  return { ...output, usage: mergeUsage(result.usage, output.usage) };
146
147
  }
@@ -282,7 +283,7 @@ export class OpenAIChatModel extends ChatModel {
282
283
  json: {
283
284
  toolCalls: toolCalls.map(({ args, ...c }) => ({
284
285
  ...c,
285
- function: { ...c.function, arguments: safeParseJSON(args) },
286
+ function: { ...c.function, arguments: args ? safeParseJSON(args) : {} },
286
287
  })),
287
288
  },
288
289
  },
@@ -298,21 +299,14 @@ export class OpenAIChatModel extends ChatModel {
298
299
  return streaming ? result : await agentResponseStreamToObject(result);
299
300
  }
300
301
  }
301
- /**
302
- * @hidden
303
- */
304
- export const ROLE_MAP = {
305
- system: "system",
306
- user: "user",
307
- agent: "assistant",
308
- tool: "tool",
309
- };
302
+ // Create role mapper for OpenAI (uses standard mapping)
303
+ const mapRole = createRoleMapper(STANDARD_ROLE_MAP);
310
304
  /**
311
305
  * @hidden
312
306
  */
313
307
  export async function contentsFromInputMessages(messages) {
314
308
  return messages.map((i) => ({
315
- role: ROLE_MAP[i.role],
309
+ role: mapRole(i.role),
316
310
  content: typeof i.content === "string"
317
311
  ? i.content
318
312
  : i.content
@@ -423,13 +417,4 @@ class CustomOpenAI extends OpenAI {
423
417
  return super.makeStatusError(status, error, message, headers);
424
418
  }
425
419
  }
426
- function safeParseJSON(text) {
427
- if (!text)
428
- return null;
429
- try {
430
- return jaison(text);
431
- }
432
- catch {
433
- return null;
434
- }
435
- }
420
+ // safeParseJSON is now imported from @aigne/core
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@aigne/openai",
3
- "version": "0.10.9",
3
+ "version": "0.10.11",
4
4
  "description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
9
- "homepage": "https://github.com/AIGNE-io/aigne-framework",
9
+ "homepage": "https://www.aigne.io/framework",
10
10
  "license": "Elastic-2.0",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/AIGNE-io/aigne-framework"
14
14
  },
15
+ "bugs": {
16
+ "url": "https://github.com/AIGNE-io/aigne-framework/issues"
17
+ },
15
18
  "files": [
16
19
  "lib/cjs",
17
20
  "lib/dts",
@@ -33,11 +36,10 @@
33
36
  },
34
37
  "dependencies": {
35
38
  "ajv": "^8.17.1",
36
- "jaison": "^2.0.2",
37
39
  "nanoid": "^5.1.5",
38
40
  "openai": "^5.8.3",
39
41
  "zod": "^3.25.67",
40
- "@aigne/core": "^1.42.0"
42
+ "@aigne/core": "^1.43.1"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@types/bun": "^1.2.18",
@@ -45,7 +47,7 @@
45
47
  "npm-run-all": "^4.1.5",
46
48
  "rimraf": "^6.0.1",
47
49
  "typescript": "^5.8.3",
48
- "@aigne/test-utils": "^0.5.17"
50
+ "@aigne/test-utils": "^0.5.19"
49
51
  },
50
52
  "scripts": {
51
53
  "lint": "tsc --noEmit",