@aigne/openai 0.8.0 → 0.8.1

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,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.1](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.8.0...openai-v0.8.1) (2025-07-09)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **model:** ensure last message is not system role for gemini ([#231](https://github.com/AIGNE-io/aigne-framework/issues/231)) ([1b72e1e](https://github.com/AIGNE-io/aigne-framework/commit/1b72e1e6be98060aa32e68585142b2eea401d109))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.32.1
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.3
18
+
3
19
  ## [0.8.0](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.7.1...openai-v0.8.0) (2025-07-08)
4
20
 
5
21
 
@@ -126,7 +126,6 @@ export declare class OpenAIChatModel extends ChatModel {
126
126
  protected apiKeyEnvName: string;
127
127
  protected apiKeyDefault: string | undefined;
128
128
  protected supportsNativeStructuredOutputs: boolean;
129
- protected supportsEndWithSystemMessage: boolean;
130
129
  protected supportsToolsUseWithJsonSchema: boolean;
131
130
  protected supportsParallelToolCalls: boolean;
132
131
  protected supportsToolsEmptyParameters: boolean;
@@ -142,7 +141,7 @@ export declare class OpenAIChatModel extends ChatModel {
142
141
  process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
143
142
  private _process;
144
143
  private getParallelToolCalls;
145
- private getRunMessages;
144
+ protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
146
145
  private getRunResponseFormat;
147
146
  private requestStructuredOutput;
148
147
  private extractResultFromStream;
@@ -75,7 +75,6 @@ class OpenAIChatModel extends core_1.ChatModel {
75
75
  apiKeyEnvName = "OPENAI_API_KEY";
76
76
  apiKeyDefault;
77
77
  supportsNativeStructuredOutputs = true;
78
- supportsEndWithSystemMessage = true;
79
78
  supportsToolsUseWithJsonSchema = true;
80
79
  supportsParallelToolCalls = true;
81
80
  supportsToolsEmptyParameters = true;
@@ -85,7 +84,7 @@ class OpenAIChatModel extends core_1.ChatModel {
85
84
  const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault;
86
85
  if (!apiKey)
87
86
  throw new Error(`Api Key is required for ${this.name}`);
88
- this._client ??= new openai_1.default({
87
+ this._client ??= new CustomOpenAI({
89
88
  baseURL: this.options?.baseURL,
90
89
  apiKey,
91
90
  ...this.options?.clientOptions,
@@ -151,9 +150,6 @@ class OpenAIChatModel extends core_1.ChatModel {
151
150
  }
152
151
  async getRunMessages(input) {
153
152
  const messages = await contentsFromInputMessages(input.messages);
154
- if (!this.supportsEndWithSystemMessage && messages.at(-1)?.role !== "user") {
155
- messages.push({ role: "user", content: "" });
156
- }
157
153
  if (!this.supportsToolsUseWithJsonSchema && input.tools?.length)
158
154
  return messages;
159
155
  if (this.supportsNativeStructuredOutputs)
@@ -417,3 +413,12 @@ function handleCompleteToolCall(toolCalls, call) {
417
413
  args: call.function?.arguments || "",
418
414
  });
419
415
  }
416
+ // Use a custom OpenAI client to handle API errors for better error messages
417
+ class CustomOpenAI extends openai_1.default {
418
+ makeStatusError(status, error, message, headers) {
419
+ if (!("error" in error) || typeof error.error !== "string") {
420
+ message = JSON.stringify(error);
421
+ }
422
+ return super.makeStatusError(status, error, message, headers);
423
+ }
424
+ }
@@ -126,7 +126,6 @@ export declare class OpenAIChatModel extends ChatModel {
126
126
  protected apiKeyEnvName: string;
127
127
  protected apiKeyDefault: string | undefined;
128
128
  protected supportsNativeStructuredOutputs: boolean;
129
- protected supportsEndWithSystemMessage: boolean;
130
129
  protected supportsToolsUseWithJsonSchema: boolean;
131
130
  protected supportsParallelToolCalls: boolean;
132
131
  protected supportsToolsEmptyParameters: boolean;
@@ -142,7 +141,7 @@ export declare class OpenAIChatModel extends ChatModel {
142
141
  process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
143
142
  private _process;
144
143
  private getParallelToolCalls;
145
- private getRunMessages;
144
+ protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
146
145
  private getRunResponseFormat;
147
146
  private requestStructuredOutput;
148
147
  private extractResultFromStream;
@@ -126,7 +126,6 @@ export declare class OpenAIChatModel extends ChatModel {
126
126
  protected apiKeyEnvName: string;
127
127
  protected apiKeyDefault: string | undefined;
128
128
  protected supportsNativeStructuredOutputs: boolean;
129
- protected supportsEndWithSystemMessage: boolean;
130
129
  protected supportsToolsUseWithJsonSchema: boolean;
131
130
  protected supportsParallelToolCalls: boolean;
132
131
  protected supportsToolsEmptyParameters: boolean;
@@ -142,7 +141,7 @@ export declare class OpenAIChatModel extends ChatModel {
142
141
  process(input: ChatModelInput): PromiseOrValue<AgentProcessResult<ChatModelOutput>>;
143
142
  private _process;
144
143
  private getParallelToolCalls;
145
- private getRunMessages;
144
+ protected getRunMessages(input: ChatModelInput): Promise<ChatCompletionMessageParam[]>;
146
145
  private getRunResponseFormat;
147
146
  private requestStructuredOutput;
148
147
  private extractResultFromStream;
@@ -66,7 +66,6 @@ export class OpenAIChatModel extends ChatModel {
66
66
  apiKeyEnvName = "OPENAI_API_KEY";
67
67
  apiKeyDefault;
68
68
  supportsNativeStructuredOutputs = true;
69
- supportsEndWithSystemMessage = true;
70
69
  supportsToolsUseWithJsonSchema = true;
71
70
  supportsParallelToolCalls = true;
72
71
  supportsToolsEmptyParameters = true;
@@ -76,7 +75,7 @@ export class OpenAIChatModel extends ChatModel {
76
75
  const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault;
77
76
  if (!apiKey)
78
77
  throw new Error(`Api Key is required for ${this.name}`);
79
- this._client ??= new OpenAI({
78
+ this._client ??= new CustomOpenAI({
80
79
  baseURL: this.options?.baseURL,
81
80
  apiKey,
82
81
  ...this.options?.clientOptions,
@@ -142,9 +141,6 @@ export class OpenAIChatModel extends ChatModel {
142
141
  }
143
142
  async getRunMessages(input) {
144
143
  const messages = await contentsFromInputMessages(input.messages);
145
- if (!this.supportsEndWithSystemMessage && messages.at(-1)?.role !== "user") {
146
- messages.push({ role: "user", content: "" });
147
- }
148
144
  if (!this.supportsToolsUseWithJsonSchema && input.tools?.length)
149
145
  return messages;
150
146
  if (this.supportsNativeStructuredOutputs)
@@ -407,3 +403,12 @@ function handleCompleteToolCall(toolCalls, call) {
407
403
  args: call.function?.arguments || "",
408
404
  });
409
405
  }
406
+ // Use a custom OpenAI client to handle API errors for better error messages
407
+ class CustomOpenAI extends OpenAI {
408
+ makeStatusError(status, error, message, headers) {
409
+ if (!("error" in error) || typeof error.error !== "string") {
410
+ message = JSON.stringify(error);
411
+ }
412
+ return super.makeStatusError(status, error, message, headers);
413
+ }
414
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/openai",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -35,7 +35,7 @@
35
35
  "nanoid": "^5.1.5",
36
36
  "openai": "^5.8.2",
37
37
  "zod": "^3.25.67",
38
- "@aigne/core": "^1.32.0"
38
+ "@aigne/core": "^1.32.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/bun": "^1.2.17",
@@ -43,7 +43,7 @@
43
43
  "npm-run-all": "^4.1.5",
44
44
  "rimraf": "^6.0.1",
45
45
  "typescript": "^5.8.3",
46
- "@aigne/test-utils": "^0.5.2"
46
+ "@aigne/test-utils": "^0.5.3"
47
47
  },
48
48
  "scripts": {
49
49
  "lint": "tsc --noEmit",