@robota-sdk/agent-provider-openai 3.0.0-beta.97 → 3.0.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 +354 -0
- package/README.md +63 -0
- package/dist/node/index.cjs +2 -2
- package/dist/node/index.d.cts +24 -2
- package/dist/node/index.d.cts.map +1 -1
- package/dist/node/index.d.ts +24 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +2 -2
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -4
- package/src/openai/__tests__/extra-body.test.ts +507 -0
- package/src/openai/__tests__/parallel-tool-policy.test.ts +398 -0
- package/src/openai/__tests__/provider-errors.test.ts +8 -3
- package/src/openai/chat-completions-chat.ts +8 -1
- package/src/openai/extra-body.ts +120 -0
- package/src/openai/parallel-tool-policy.ts +25 -0
- package/src/openai/provider-definition.ts +9 -0
- package/src/openai/provider.ts +21 -1
- package/src/openai/responses-chat.ts +7 -1
- package/src/openai/responses-types.ts +1 -0
- package/src/openai/types.ts +29 -0
package/src/openai/provider.ts
CHANGED
|
@@ -11,12 +11,14 @@ import {
|
|
|
11
11
|
chatStreamWithOpenAIChatCompletions,
|
|
12
12
|
chatWithOpenAIChatCompletions,
|
|
13
13
|
} from './chat-completions-chat';
|
|
14
|
+
import { assertExtraBodyExecutor, parseExtraBody } from './extra-body';
|
|
14
15
|
import { OPENAI_MODEL_EFFORT_TABLE } from './model-effort-table';
|
|
16
|
+
import { assertParallelToolCallsExecutor, parseParallelToolCalls } from './parallel-tool-policy';
|
|
15
17
|
import { OpenAIResponseParser } from './parsers/response-parser';
|
|
16
18
|
import { chatStreamWithOpenAIResponsesApi, chatWithOpenAIResponsesApi } from './responses-chat';
|
|
17
19
|
|
|
18
20
|
import type { IPayloadLogger } from './interfaces/payload-logger';
|
|
19
|
-
import type { IOpenAIProviderOptions, TOpenAIApiSurface } from './types';
|
|
21
|
+
import type { IOpenAIProviderOptions, TOpenAIApiSurface, TOpenAIExtraBody } from './types';
|
|
20
22
|
import type {
|
|
21
23
|
TUniversalMessage,
|
|
22
24
|
IChatOptions,
|
|
@@ -42,6 +44,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
42
44
|
private readonly client?: OpenAI;
|
|
43
45
|
private readonly options: IOpenAIProviderOptions;
|
|
44
46
|
private readonly apiSurface: TOpenAIApiSurface;
|
|
47
|
+
private readonly parallelToolCalls: boolean | undefined;
|
|
48
|
+
private readonly extraBody: TOpenAIExtraBody | undefined;
|
|
45
49
|
private readonly payloadLogger: IPayloadLogger | undefined;
|
|
46
50
|
private readonly responseParser: OpenAIResponseParser;
|
|
47
51
|
|
|
@@ -56,6 +60,10 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
56
60
|
constructor(options: IOpenAIProviderOptions) {
|
|
57
61
|
super(options.logger || SilentLogger);
|
|
58
62
|
this.options = options;
|
|
63
|
+
this.parallelToolCalls = parseParallelToolCalls(options.parallelToolCalls, options.apiSurface);
|
|
64
|
+
assertParallelToolCallsExecutor(this.parallelToolCalls, options.executor !== undefined);
|
|
65
|
+
this.extraBody = parseExtraBody(options.extraBody);
|
|
66
|
+
assertExtraBodyExecutor(this.extraBody, options.executor !== undefined);
|
|
59
67
|
this.apiSurface = resolveApiSurface(options);
|
|
60
68
|
validateOpenAIProviderNativeWebTools(this.apiSurface, options.nativeWebTools);
|
|
61
69
|
|
|
@@ -86,6 +94,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
86
94
|
messages: TUniversalMessage[],
|
|
87
95
|
options?: IChatOptions,
|
|
88
96
|
): Promise<TUniversalMessage> {
|
|
97
|
+
assertParallelToolCallsExecutor(this.parallelToolCalls, this.executor !== undefined);
|
|
98
|
+
assertExtraBodyExecutor(this.extraBody, this.executor !== undefined);
|
|
89
99
|
this.validateMessages(messages);
|
|
90
100
|
this.validateNativeWebTools(options?.nativeWebTools);
|
|
91
101
|
const resolvedOptions = this.resolveEffortOptions(options);
|
|
@@ -112,6 +122,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
112
122
|
messages,
|
|
113
123
|
chatOptions: this.projectChatOptions(resolvedOptions),
|
|
114
124
|
providerOptions: this.options,
|
|
125
|
+
parallelToolCalls: this.parallelToolCalls,
|
|
126
|
+
extraBody: this.extraBody,
|
|
115
127
|
onTextDelta: this.onTextDelta,
|
|
116
128
|
requestHeaders: this.traceRequestHeaders(resolvedOptions),
|
|
117
129
|
});
|
|
@@ -124,6 +136,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
124
136
|
messages,
|
|
125
137
|
chatOptions: this.projectChatOptions(resolvedOptions),
|
|
126
138
|
providerOptions: this.options,
|
|
139
|
+
parallelToolCalls: this.parallelToolCalls,
|
|
140
|
+
extraBody: this.extraBody,
|
|
127
141
|
payloadLogger: this.payloadLogger,
|
|
128
142
|
responseParser: this.responseParser,
|
|
129
143
|
onTextDelta: this.onTextDelta,
|
|
@@ -137,6 +151,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
137
151
|
messages: TUniversalMessage[],
|
|
138
152
|
options?: IChatOptions,
|
|
139
153
|
): AsyncIterable<TUniversalMessage> {
|
|
154
|
+
assertParallelToolCallsExecutor(this.parallelToolCalls, this.executor !== undefined);
|
|
155
|
+
assertExtraBodyExecutor(this.extraBody, this.executor !== undefined);
|
|
140
156
|
this.validateNativeWebTools(options?.nativeWebTools);
|
|
141
157
|
const resolvedOptions = this.resolveEffortOptions(options);
|
|
142
158
|
|
|
@@ -179,6 +195,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
179
195
|
messages,
|
|
180
196
|
chatOptions: this.projectChatOptions(resolvedOptions),
|
|
181
197
|
providerOptions: this.options,
|
|
198
|
+
parallelToolCalls: this.parallelToolCalls,
|
|
199
|
+
extraBody: this.extraBody,
|
|
182
200
|
onTextDelta: this.onTextDelta,
|
|
183
201
|
requestHeaders: this.traceRequestHeaders(resolvedOptions),
|
|
184
202
|
});
|
|
@@ -191,6 +209,8 @@ export class OpenAIProvider extends AbstractAIProvider {
|
|
|
191
209
|
messages,
|
|
192
210
|
chatOptions: this.projectChatOptions(resolvedOptions),
|
|
193
211
|
providerOptions: this.options,
|
|
212
|
+
parallelToolCalls: this.parallelToolCalls,
|
|
213
|
+
extraBody: this.extraBody,
|
|
194
214
|
payloadLogger: this.payloadLogger,
|
|
195
215
|
responseParser: this.responseParser,
|
|
196
216
|
onTextDelta: this.onTextDelta,
|
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
toOpenAIResponsesToolChoice,
|
|
8
8
|
} from '@robota-sdk/agent-provider-openai-compatible/shared';
|
|
9
9
|
|
|
10
|
+
import { extraBodyWire } from './extra-body';
|
|
10
11
|
import { buildOpenAIResponsesTextConfig } from './openai-request-format';
|
|
12
|
+
import { parallelToolCallsWire } from './parallel-tool-policy';
|
|
11
13
|
import { resolveOpenAIReasoningOptions } from './reasoning-effort';
|
|
12
14
|
import {
|
|
13
15
|
awaitWithProviderRequestId,
|
|
@@ -26,7 +28,7 @@ import type {
|
|
|
26
28
|
IOpenAIResponsesRequestStreaming,
|
|
27
29
|
TOpenAIResponsesStreamEvent,
|
|
28
30
|
} from './responses-types';
|
|
29
|
-
import type { IOpenAIProviderOptions } from './types';
|
|
31
|
+
import type { IOpenAIProviderOptions, TOpenAIExtraBody } from './types';
|
|
30
32
|
import type { IChatOptions, TTextDeltaCallback, TUniversalMessage } from '@robota-sdk/agent-core';
|
|
31
33
|
import type OpenAI from 'openai';
|
|
32
34
|
|
|
@@ -35,6 +37,8 @@ export interface IOpenAIResponsesChatOptions {
|
|
|
35
37
|
messages: TUniversalMessage[];
|
|
36
38
|
chatOptions?: IChatOptions;
|
|
37
39
|
providerOptions: IOpenAIProviderOptions;
|
|
40
|
+
parallelToolCalls?: boolean;
|
|
41
|
+
extraBody?: TOpenAIExtraBody;
|
|
38
42
|
onTextDelta?: TTextDeltaCallback;
|
|
39
43
|
/** Per-request headers (trusted `traceparent`), sent after the raw request payload is captured. */
|
|
40
44
|
requestHeaders?: Readonly<Record<string, string>>;
|
|
@@ -176,7 +180,9 @@ function buildResponsesRequestParams(
|
|
|
176
180
|
input.chatOptions?.effortResolution,
|
|
177
181
|
);
|
|
178
182
|
return {
|
|
183
|
+
...extraBodyWire(input.extraBody),
|
|
179
184
|
model,
|
|
185
|
+
...parallelToolCallsWire(input.parallelToolCalls),
|
|
180
186
|
input: convertToOpenAIResponsesInput(input.messages),
|
|
181
187
|
...(tools !== undefined && {
|
|
182
188
|
tools,
|
|
@@ -79,6 +79,7 @@ export interface IOpenAIResponsesTextConfig {
|
|
|
79
79
|
|
|
80
80
|
export interface IOpenAIResponsesRequestBase {
|
|
81
81
|
model: string;
|
|
82
|
+
parallel_tool_calls?: boolean;
|
|
82
83
|
input: TOpenAIResponsesInputItem[];
|
|
83
84
|
tools?: TOpenAIResponsesTool[];
|
|
84
85
|
tool_choice?: 'auto' | 'none' | 'required' | { type: 'function'; name: string };
|
package/src/openai/types.ts
CHANGED
|
@@ -21,6 +21,18 @@ export interface IOpenAINativeWebToolsOptions {
|
|
|
21
21
|
webFetch?: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/** A JSON value sent through {@link IOpenAIProviderOptions.extraBody}. */
|
|
25
|
+
export type TOpenAIExtraBodyValue =
|
|
26
|
+
| string
|
|
27
|
+
| number
|
|
28
|
+
| boolean
|
|
29
|
+
| null
|
|
30
|
+
| readonly TOpenAIExtraBodyValue[]
|
|
31
|
+
| { readonly [key: string]: TOpenAIExtraBodyValue };
|
|
32
|
+
|
|
33
|
+
/** Top-level request-body fields sent through {@link IOpenAIProviderOptions.extraBody}. */
|
|
34
|
+
export type TOpenAIExtraBody = Readonly<Record<string, TOpenAIExtraBodyValue>>;
|
|
35
|
+
|
|
24
36
|
/**
|
|
25
37
|
* Valid provider option value types
|
|
26
38
|
*/
|
|
@@ -33,6 +45,7 @@ export type TOpenAIProviderOptionValue =
|
|
|
33
45
|
| IOpenAIJsonSchemaDefinition
|
|
34
46
|
| IOpenAINativeWebToolsOptions
|
|
35
47
|
| IOpenAIResponsesReasoningOptions
|
|
48
|
+
| TOpenAIExtraBody
|
|
36
49
|
| OpenAI
|
|
37
50
|
| IPayloadLogger
|
|
38
51
|
| ILogger
|
|
@@ -164,6 +177,22 @@ export interface IOpenAIProviderOptions {
|
|
|
164
177
|
*/
|
|
165
178
|
strictTools?: boolean;
|
|
166
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Requests the native parallel function-call generation policy: on Chat Completions only with
|
|
182
|
+
* tools, on Responses with every request.
|
|
183
|
+
* Captured at construction; undefined omits the wire field. Does not guarantee call count,
|
|
184
|
+
* argument validity or execution order. Explicit values cannot be used with an executor.
|
|
185
|
+
*/
|
|
186
|
+
readonly parallelToolCalls?: boolean;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* JSON fields merged as top-level fields into every request body on both API surfaces, for
|
|
190
|
+
* endpoint-specific options this provider does not model (for example a gateway's upstream
|
|
191
|
+
* options). Copied at construction; an empty object is the same as omitting it. Fields the
|
|
192
|
+
* provider manages and non-JSON values are rejected, and it cannot be used with an executor.
|
|
193
|
+
*/
|
|
194
|
+
readonly extraBody?: TOpenAIExtraBody;
|
|
195
|
+
|
|
167
196
|
/**
|
|
168
197
|
* Provider-native hosted web tool request from provider profile options.
|
|
169
198
|
*
|