@robota-sdk/agent-provider-openai 3.0.0-beta.63 → 3.0.0-beta.82
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/LICENSE +661 -21
- package/dist/node/index.cjs +1 -2
- package/dist/node/index.d.cts +271 -267
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.ts +271 -267
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +2 -2
- package/dist/node/index.js.map +1 -0
- package/dist/node/loggers/index.cjs +1 -0
- package/dist/node/loggers/index.d.cts +94 -0
- package/dist/node/loggers/index.d.cts.map +1 -0
- package/dist/node/loggers/index.d.ts +94 -0
- package/dist/node/loggers/index.d.ts.map +1 -0
- package/dist/node/loggers/index.js +2 -0
- package/dist/node/loggers/index.js.map +1 -0
- package/dist/node/payload-logger-BaW0K8yI.d.cts +61 -0
- package/dist/node/payload-logger-BaW0K8yI.d.cts.map +1 -0
- package/dist/node/payload-logger-BaW0K8yI.d.ts +61 -0
- package/dist/node/payload-logger-BaW0K8yI.d.ts.map +1 -0
- package/dist/node/rolldown-runtime-CMqjfN_6.cjs +1 -0
- package/package.json +69 -86
- package/src/index.ts +1 -0
- package/src/openai/__tests__/endpoint-provenance.test.ts +44 -0
- package/src/openai/__tests__/provider-errors.test.ts +114 -0
- package/src/openai/__tests__/request-format.test.ts +59 -0
- package/src/openai/__tests__/strict-tools-closure.test.ts +136 -0
- package/src/openai/__tests__/tool-schema-projection.test.ts +302 -0
- package/src/openai/__tests__/trace-context-wire.test.ts +114 -0
- package/src/openai/adapter.test.ts +494 -0
- package/src/openai/adapter.ts +145 -0
- package/src/openai/chat-completions-chat.ts +225 -0
- package/src/openai/executor-integration.test.ts +213 -0
- package/src/openai/index.ts +19 -0
- package/src/openai/interfaces/payload-logger.ts +48 -0
- package/src/openai/loggers/console-payload-logger.test.ts +173 -0
- package/src/openai/loggers/console-payload-logger.ts +96 -0
- package/src/openai/loggers/console.ts +9 -0
- package/src/openai/loggers/file-payload-logger.test.ts +243 -0
- package/src/openai/loggers/file-payload-logger.ts +124 -0
- package/src/openai/loggers/file.ts +9 -0
- package/src/openai/loggers/index.ts +12 -0
- package/src/openai/loggers/sanitize-openai-log-data.test.ts +89 -0
- package/src/openai/loggers/sanitize-openai-log-data.ts +14 -0
- package/src/openai/message-converter.ts +23 -0
- package/src/openai/model-effort-table.ts +19 -0
- package/src/openai/model-effort-verification-config.test.ts +45 -0
- package/src/openai/model-effort-verification-config.ts +35 -0
- package/src/openai/openai-request-format.ts +116 -0
- package/src/openai/parsers/response-parser.test.ts +407 -0
- package/src/openai/parsers/response-parser.ts +48 -0
- package/src/openai/provider-definition.test.ts +74 -0
- package/src/openai/provider-definition.ts +139 -0
- package/src/openai/provider.test.ts +1686 -0
- package/src/openai/provider.ts +392 -0
- package/src/openai/reasoning-effort.test.ts +272 -0
- package/src/openai/reasoning-effort.ts +49 -0
- package/src/openai/request-id.ts +39 -0
- package/src/openai/request-options.ts +14 -0
- package/src/openai/responses-chat.ts +285 -0
- package/src/openai/responses-converter.ts +122 -0
- package/src/openai/responses-parser.ts +297 -0
- package/src/openai/responses-stream-utils.ts +45 -0
- package/src/openai/responses-types.ts +193 -0
- package/src/openai/streaming/stream-assembler.ts +3 -0
- package/src/openai/types/api-types.ts +113 -0
- package/src/openai/types.ts +235 -0
- package/CHANGELOG.md +0 -614
- package/README.md +0 -467
- package/dist/browser/index.d.ts +0 -307
- package/dist/browser/index.js +0 -2
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { IPayloadLogger } from './interfaces/payload-logger';
|
|
2
|
+
import type { IExecutor, ILogger, TProviderOptionValueBase } from '@robota-sdk/agent-core';
|
|
3
|
+
import type OpenAI from 'openai';
|
|
4
|
+
|
|
5
|
+
export type TOpenAIApiSurface = 'responses' | 'chat-completions';
|
|
6
|
+
|
|
7
|
+
export interface IOpenAIJsonSchemaDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
schema?: Record<string, TOpenAIProviderOptionValue>;
|
|
11
|
+
strict?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IOpenAIResponsesReasoningOptions {
|
|
15
|
+
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
16
|
+
summary?: 'auto' | 'concise' | 'detailed';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IOpenAINativeWebToolsOptions {
|
|
20
|
+
webSearch?: boolean;
|
|
21
|
+
webFetch?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Valid provider option value types
|
|
26
|
+
*/
|
|
27
|
+
export type TOpenAIProviderOptionValue =
|
|
28
|
+
| string
|
|
29
|
+
| number
|
|
30
|
+
| boolean
|
|
31
|
+
| undefined
|
|
32
|
+
| null
|
|
33
|
+
| IOpenAIJsonSchemaDefinition
|
|
34
|
+
| IOpenAINativeWebToolsOptions
|
|
35
|
+
| IOpenAIResponsesReasoningOptions
|
|
36
|
+
| OpenAI
|
|
37
|
+
| IPayloadLogger
|
|
38
|
+
| ILogger
|
|
39
|
+
| IExecutor
|
|
40
|
+
| TProviderOptionValueBase
|
|
41
|
+
| TOpenAIProviderOptionValue[]
|
|
42
|
+
| { [key: string]: TOpenAIProviderOptionValue };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* OpenAI provider options
|
|
46
|
+
*/
|
|
47
|
+
export interface IOpenAIProviderOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Additional provider-specific options
|
|
50
|
+
*/
|
|
51
|
+
[key: string]: TOpenAIProviderOptionValue;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* OpenAI API key (required when client is not provided)
|
|
55
|
+
*/
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* OpenAI organization ID (optional)
|
|
60
|
+
*/
|
|
61
|
+
organization?: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* API request timeout (milliseconds)
|
|
65
|
+
*/
|
|
66
|
+
timeout?: number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Whether to request token usage on streaming turns via
|
|
70
|
+
* `stream_options: { include_usage: true }` (default `true`). Set `false` for
|
|
71
|
+
* OpenAI-compatible endpoints that reject `stream_options`; usage is then absent
|
|
72
|
+
* on streaming turns for this provider.
|
|
73
|
+
*/
|
|
74
|
+
includeStreamUsage?: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* API base URL (default: `'https://api.openai.com/v1'`).
|
|
78
|
+
*
|
|
79
|
+
* Point this at ANY OpenAI-compatible endpoint — this provider is a protocol
|
|
80
|
+
* client, not an OpenAI-vendor lock:
|
|
81
|
+
*
|
|
82
|
+
* - AI gateways: Vercel AI Gateway, LiteLLM, OpenRouter, …
|
|
83
|
+
* - Hosted compatibles: Azure OpenAI, Groq, Together, …
|
|
84
|
+
* - Local/self-hosted: vLLM, Ollama, LM Studio, …
|
|
85
|
+
*
|
|
86
|
+
* Setting `baseURL` switches the default {@link apiSurface} to
|
|
87
|
+
* `'chat-completions'` for broad endpoint compatibility (official OpenAI calls
|
|
88
|
+
* default to the Responses API). Model slugs are passed through verbatim, so
|
|
89
|
+
* gateway-namespaced ids like `anthropic/claude-sonnet-4-5` or
|
|
90
|
+
* `meta-llama/llama-3.1-70b` work as `defaultModel`/`model` values — streaming
|
|
91
|
+
* and tool calling ride the same chat-completions protocol.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* // Vercel AI Gateway with a non-OpenAI model slug
|
|
96
|
+
* createOpenAIProvider({
|
|
97
|
+
* apiKey: process.env.AI_GATEWAY_API_KEY,
|
|
98
|
+
* baseURL: 'https://ai-gateway.vercel.sh/v1',
|
|
99
|
+
* defaultModel: 'anthropic/claude-sonnet-4-5',
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
baseURL?: string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Default model used when chat options do not provide a model.
|
|
107
|
+
*/
|
|
108
|
+
defaultModel?: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* API surface to use for direct OpenAI calls.
|
|
112
|
+
*
|
|
113
|
+
* Defaults to Responses for official OpenAI calls. Profiles with baseURL use
|
|
114
|
+
* Chat Completions by default for OpenAI-compatible endpoint compatibility.
|
|
115
|
+
*/
|
|
116
|
+
apiSurface?: TOpenAIApiSurface;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Response format (default: 'text')
|
|
120
|
+
* - 'text': Plain text response
|
|
121
|
+
* - 'json_object': JSON object mode (requires system message)
|
|
122
|
+
* - 'json_schema': Structured Outputs with schema validation
|
|
123
|
+
*/
|
|
124
|
+
responseFormat?: 'text' | 'json_object' | 'json_schema';
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* JSON schema for structured outputs (required when responseFormat is 'json_schema')
|
|
128
|
+
*/
|
|
129
|
+
jsonSchema?: IOpenAIJsonSchemaDefinition;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Responses API reasoning controls. Hidden reasoning is never exposed in message
|
|
133
|
+
* content; only explicit summaries/encrypted items requested here are represented.
|
|
134
|
+
*/
|
|
135
|
+
reasoning?: IOpenAIResponsesReasoningOptions;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether OpenAI should store Responses API results. Defaults to OpenAI API behavior.
|
|
139
|
+
*/
|
|
140
|
+
store?: boolean;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Include encrypted reasoning items for stateless reasoning continuation.
|
|
144
|
+
*/
|
|
145
|
+
includeEncryptedReasoning?: boolean;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Opt into strict custom function parameter validation where supported.
|
|
149
|
+
*
|
|
150
|
+
* PROV-007: the tool schema is rewritten for strict mode on the way out — every object node,
|
|
151
|
+
* nested ones included, is closed and given a complete `required` list. That transformation is
|
|
152
|
+
* lossy, so it runs ONLY when this flag is on; with it off the schema is forwarded exactly as
|
|
153
|
+
* authored.
|
|
154
|
+
*
|
|
155
|
+
* What "lossy" means for a caller: strict mode has no way to say "optional", so a field the
|
|
156
|
+
* schema marked optional becomes required and gains a `null` branch. The model must then supply
|
|
157
|
+
* the key explicitly, with `null` standing for "not provided". A tool whose handler distinguishes
|
|
158
|
+
* an absent key from a null value will see the difference.
|
|
159
|
+
*/
|
|
160
|
+
strictTools?: boolean;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Provider-native hosted web tool request from provider profile options.
|
|
164
|
+
*
|
|
165
|
+
* OpenAI-compatible Chat Completions endpoints do not support this Robota
|
|
166
|
+
* native web contract. The provider rejects unsupported configurations before
|
|
167
|
+
* any model request is sent.
|
|
168
|
+
*/
|
|
169
|
+
nativeWebTools?: IOpenAINativeWebToolsOptions;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* OpenAI client instance (optional: will be created from apiKey if not provided)
|
|
173
|
+
*/
|
|
174
|
+
client?: OpenAI;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Payload logger instance for debugging API requests/responses
|
|
178
|
+
*
|
|
179
|
+
* Use different implementations based on your environment:
|
|
180
|
+
* - FilePayloadLogger: Node.js file-based logging
|
|
181
|
+
* - ConsolePayloadLogger: Browser console-based logging
|
|
182
|
+
* - Custom: Implement IPayloadLogger interface
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // Node.js
|
|
187
|
+
* import { FilePayloadLogger } from '@robota-sdk/agent-provider-openai/loggers';
|
|
188
|
+
* const provider = new OpenAIProvider({
|
|
189
|
+
* client: openaiClient,
|
|
190
|
+
* payloadLogger: new FilePayloadLogger({ logDir: './logs/openai' })
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Browser
|
|
194
|
+
* import { ConsolePayloadLogger } from '@robota-sdk/agent-provider-openai/loggers';
|
|
195
|
+
* const provider = new OpenAIProvider({
|
|
196
|
+
* client: openaiClient,
|
|
197
|
+
* payloadLogger: new ConsolePayloadLogger()
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
payloadLogger?: IPayloadLogger;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Optional executor for handling AI requests
|
|
205
|
+
*
|
|
206
|
+
* When provided, the provider will delegate all chat operations to this executor
|
|
207
|
+
* instead of making direct API calls. This enables remote execution capabilities.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* import { LocalExecutor, RemoteExecutor } from '@robota-sdk/agent-core';
|
|
212
|
+
*
|
|
213
|
+
* // Local execution (registers this provider)
|
|
214
|
+
* const localExecutor = new LocalExecutor();
|
|
215
|
+
* localExecutor.registerProvider('openai', new OpenAIProvider({ apiKey: 'sk-...' }));
|
|
216
|
+
*
|
|
217
|
+
* // Remote execution
|
|
218
|
+
* const remoteExecutor = new RemoteExecutor({
|
|
219
|
+
* serverUrl: 'https://api.robota.io',
|
|
220
|
+
* userApiKey: 'user-token-123'
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* const provider = new OpenAIProvider({
|
|
224
|
+
* executor: remoteExecutor // No direct API key needed
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
executor?: IExecutor;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Logger instance for internal OpenAI provider logging
|
|
232
|
+
* @defaultValue SilentLogger
|
|
233
|
+
*/
|
|
234
|
+
logger?: ILogger;
|
|
235
|
+
}
|