@robota-sdk/agent-provider-openai 3.0.0-beta.99 → 3.0.2

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.
@@ -1,5 +1,6 @@
1
1
  import { probeOpenAICompatibleProfile } from '@robota-sdk/agent-provider-openai-compatible/shared';
2
2
 
3
+ import { parseExtraBody } from './extra-body';
3
4
  import { OpenAIProvider } from './provider';
4
5
  import { parseParallelToolCalls } from './parallel-tool-policy';
5
6
 
@@ -64,6 +65,7 @@ export function createOpenAIProviderDefinition(): IProviderDefinition {
64
65
  config.options?.parallelToolCalls,
65
66
  config.options?.apiSurface,
66
67
  );
68
+ const extraBody = parseExtraBody(config.options?.extraBody);
67
69
  const apiSurface = readApiSurface(config.options);
68
70
  const nativeWebTools = readNativeWebTools(config.options);
69
71
  validateOpenAINativeWebTools(config.baseURL, apiSurface, nativeWebTools);
@@ -73,6 +75,7 @@ export function createOpenAIProviderDefinition(): IProviderDefinition {
73
75
  ...(config.timeout !== undefined && { timeout: config.timeout }),
74
76
  ...(apiSurface !== undefined && { apiSurface }),
75
77
  ...(parallelToolCalls !== undefined && { parallelToolCalls }),
78
+ ...(extraBody !== undefined && { extraBody }),
76
79
  ...(nativeWebTools !== undefined && { nativeWebTools }),
77
80
  ...(config.options?.durableOperations === true && { durableOperations: true }),
78
81
  defaultModel: config.model,
@@ -11,13 +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';
15
16
  import { assertParallelToolCallsExecutor, parseParallelToolCalls } from './parallel-tool-policy';
16
17
  import { OpenAIResponseParser } from './parsers/response-parser';
17
18
  import { chatStreamWithOpenAIResponsesApi, chatWithOpenAIResponsesApi } from './responses-chat';
18
19
 
19
20
  import type { IPayloadLogger } from './interfaces/payload-logger';
20
- import type { IOpenAIProviderOptions, TOpenAIApiSurface } from './types';
21
+ import type { IOpenAIProviderOptions, TOpenAIApiSurface, TOpenAIExtraBody } from './types';
21
22
  import type {
22
23
  TUniversalMessage,
23
24
  IChatOptions,
@@ -44,6 +45,7 @@ export class OpenAIProvider extends AbstractAIProvider {
44
45
  private readonly options: IOpenAIProviderOptions;
45
46
  private readonly apiSurface: TOpenAIApiSurface;
46
47
  private readonly parallelToolCalls: boolean | undefined;
48
+ private readonly extraBody: TOpenAIExtraBody | undefined;
47
49
  private readonly payloadLogger: IPayloadLogger | undefined;
48
50
  private readonly responseParser: OpenAIResponseParser;
49
51
 
@@ -60,6 +62,8 @@ export class OpenAIProvider extends AbstractAIProvider {
60
62
  this.options = options;
61
63
  this.parallelToolCalls = parseParallelToolCalls(options.parallelToolCalls, options.apiSurface);
62
64
  assertParallelToolCallsExecutor(this.parallelToolCalls, options.executor !== undefined);
65
+ this.extraBody = parseExtraBody(options.extraBody);
66
+ assertExtraBodyExecutor(this.extraBody, options.executor !== undefined);
63
67
  this.apiSurface = resolveApiSurface(options);
64
68
  validateOpenAIProviderNativeWebTools(this.apiSurface, options.nativeWebTools);
65
69
 
@@ -91,6 +95,7 @@ export class OpenAIProvider extends AbstractAIProvider {
91
95
  options?: IChatOptions,
92
96
  ): Promise<TUniversalMessage> {
93
97
  assertParallelToolCallsExecutor(this.parallelToolCalls, this.executor !== undefined);
98
+ assertExtraBodyExecutor(this.extraBody, this.executor !== undefined);
94
99
  this.validateMessages(messages);
95
100
  this.validateNativeWebTools(options?.nativeWebTools);
96
101
  const resolvedOptions = this.resolveEffortOptions(options);
@@ -118,6 +123,7 @@ export class OpenAIProvider extends AbstractAIProvider {
118
123
  chatOptions: this.projectChatOptions(resolvedOptions),
119
124
  providerOptions: this.options,
120
125
  parallelToolCalls: this.parallelToolCalls,
126
+ extraBody: this.extraBody,
121
127
  onTextDelta: this.onTextDelta,
122
128
  requestHeaders: this.traceRequestHeaders(resolvedOptions),
123
129
  });
@@ -131,6 +137,7 @@ export class OpenAIProvider extends AbstractAIProvider {
131
137
  chatOptions: this.projectChatOptions(resolvedOptions),
132
138
  providerOptions: this.options,
133
139
  parallelToolCalls: this.parallelToolCalls,
140
+ extraBody: this.extraBody,
134
141
  payloadLogger: this.payloadLogger,
135
142
  responseParser: this.responseParser,
136
143
  onTextDelta: this.onTextDelta,
@@ -145,6 +152,7 @@ export class OpenAIProvider extends AbstractAIProvider {
145
152
  options?: IChatOptions,
146
153
  ): AsyncIterable<TUniversalMessage> {
147
154
  assertParallelToolCallsExecutor(this.parallelToolCalls, this.executor !== undefined);
155
+ assertExtraBodyExecutor(this.extraBody, this.executor !== undefined);
148
156
  this.validateNativeWebTools(options?.nativeWebTools);
149
157
  const resolvedOptions = this.resolveEffortOptions(options);
150
158
 
@@ -188,6 +196,7 @@ export class OpenAIProvider extends AbstractAIProvider {
188
196
  chatOptions: this.projectChatOptions(resolvedOptions),
189
197
  providerOptions: this.options,
190
198
  parallelToolCalls: this.parallelToolCalls,
199
+ extraBody: this.extraBody,
191
200
  onTextDelta: this.onTextDelta,
192
201
  requestHeaders: this.traceRequestHeaders(resolvedOptions),
193
202
  });
@@ -201,6 +210,7 @@ export class OpenAIProvider extends AbstractAIProvider {
201
210
  chatOptions: this.projectChatOptions(resolvedOptions),
202
211
  providerOptions: this.options,
203
212
  parallelToolCalls: this.parallelToolCalls,
213
+ extraBody: this.extraBody,
204
214
  payloadLogger: this.payloadLogger,
205
215
  responseParser: this.responseParser,
206
216
  onTextDelta: this.onTextDelta,
@@ -7,6 +7,7 @@ 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';
11
12
  import { parallelToolCallsWire } from './parallel-tool-policy';
12
13
  import { resolveOpenAIReasoningOptions } from './reasoning-effort';
@@ -27,7 +28,7 @@ import type {
27
28
  IOpenAIResponsesRequestStreaming,
28
29
  TOpenAIResponsesStreamEvent,
29
30
  } from './responses-types';
30
- import type { IOpenAIProviderOptions } from './types';
31
+ import type { IOpenAIProviderOptions, TOpenAIExtraBody } from './types';
31
32
  import type { IChatOptions, TTextDeltaCallback, TUniversalMessage } from '@robota-sdk/agent-core';
32
33
  import type OpenAI from 'openai';
33
34
 
@@ -37,6 +38,7 @@ export interface IOpenAIResponsesChatOptions {
37
38
  chatOptions?: IChatOptions;
38
39
  providerOptions: IOpenAIProviderOptions;
39
40
  parallelToolCalls?: boolean;
41
+ extraBody?: TOpenAIExtraBody;
40
42
  onTextDelta?: TTextDeltaCallback;
41
43
  /** Per-request headers (trusted `traceparent`), sent after the raw request payload is captured. */
42
44
  requestHeaders?: Readonly<Record<string, string>>;
@@ -178,6 +180,7 @@ function buildResponsesRequestParams(
178
180
  input.chatOptions?.effortResolution,
179
181
  );
180
182
  return {
183
+ ...extraBodyWire(input.extraBody),
181
184
  model,
182
185
  ...parallelToolCallsWire(input.parallelToolCalls),
183
186
  input: convertToOpenAIResponsesInput(input.messages),
@@ -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
@@ -172,6 +185,14 @@ export interface IOpenAIProviderOptions {
172
185
  */
173
186
  readonly parallelToolCalls?: boolean;
174
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
+
175
196
  /**
176
197
  * Provider-native hosted web tool request from provider profile options.
177
198
  *